Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python noob: "ImportError: No module named internet"

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.

like image 969
Eamorr Avatar asked Nov 30 '22 07:11

Eamorr


1 Answers

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.

like image 145
Achim Avatar answered Dec 05 '22 21:12

Achim