Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named twisted

Tags:

python

pydev

I'm pretty new to python and twisted and I tried to run a simple twisted script but failed.

My environment:

MacOX 10.7.2 + Python 2.7.1 + Twisted 11.0.0 + eclipse + PyDev

The script called test.py:

from twisted import reactor
reactor.run()

I tried to run it in the terminal and everything works fine.

Then I opened eclipse and created a new PyDev project then adding a py file called test.py and typed the code above in.

When I tried to run it I got errors like:

Traceback (most recent call last):
File "/Users/user/Documents/workspace/TwistedDemo/test.py", line 2, in <module>
from twisted import reactor
ImportError: No module named twisted

Then I checked the PYTHONPATH and added the "twisted source folder" in the external libraries tab but the errors was still there.(nothing changed)

Hope someone can help me out here, thanks in advance :)

like image 260
supersuraccoon Avatar asked Jul 10 '12 02:07

supersuraccoon


1 Answers

Several things to try here -

  1. Since your env is Mac OSX. I installed commandline tools from Xcode which solved this problem. Xcode 4.4 and later install Command Line Tools

  2. For the sake of completeness. If this on Ubuntu, then apt-get install python-twisted generally works.

  3. from your eclipse put this in your python script -

    python -c 'import sys;print sys.path'

    This tells all the paths that python looks for when you import something. If you don't find twisted path there then add it to this like so - sys.path.append(twisted_dir_path)

  4. Finally, if all the above does not help. type -p python in a shell will tell you which version you're using; I would mostly be /usr/bin/ or some variant of it.

    Then /usr/bin/python2.7 -c 'from twisted.internet.protocol import Factory,Protocol' ought to succeed.

like image 61
Srikar Appalaraju Avatar answered Nov 13 '22 17:11

Srikar Appalaraju