I'm trying to get Python twisted to work on my Ubuntu 11.04 box.
I did sudo apt-get install python-twisted
However, when I try the following code:
from twisted.internet import protocol, reactor
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
reactor.listenTCP(1234, EchoFactory())
reactor.run()
I get this error which I cannot get to the bottom of:
Traceback (most recent call last):
File "eamorr.py", line 1, in <module>
from twisted.internet import protocol, reactor
File "/home/eamorr/Desktop/twisted.py", line 1, in <module>
ImportError: No module named internet
Any help is most appreciated.
The problem is the name of your file. Python looks first in your current directory for modules. When you try to import twisted.internet
it finds the file in your folder, which is called twisted.py
. But there can not internet
submodule be found. If you rename your file, Python will load the correct twisted
and everything will be finde.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With