Question

I am trying to import python-twitter on Eclipse with Python 2.7.3 and PyDev 2.5 I downloaded it as follows.

pip install twitter

Eclipse doesn't recognize it, instead saying:

Traceback (most recent call last):
  File "/Users/Jen/Documents/workspace/drugs/src/marijuana.py", line 1, in <module>
    import twitter as twitter
ImportError: No module named twitter

I have the same error when trying to import Matplotlib, Scipy, SimpleJSON and NLTK. In fact, the only module I can import is NumPy. So, I think the PyDev plugin for Eclipse might not know that these files were added to PYTHONPATH?

Any advice on how to proceed?

Was it helpful?

Solution

In eclipse, even if you install something on your machine, you need to refresh your python configuration in eclipse - it doesn't recognize changes manually. (This is so it can store multiple configurations.)

On OSX, this is under Preferences -> PyDev -> Interperter-Python

From here, I usually remove the configuration and run auto config again, but you can also just add the folder manually.

If the folder is in configuration, and it still doesn't work, you can verify the system path by starting an interpreter and typing:

import sys
print sys.path

If it's not there, then try refreshing the interpreter again... and verifying that it picks up the import. You also might check out How to Configure Eclipse from this post How to persist PYTHONPATH setting of an Eclipse Pydev project?

And verify that it's installed correctly, by opening a terminal (on your mac, not in eclipse), and starting python from there, and verifying that it works.

OTHER TIPS

I installed Python-Twitter but then had to add the egg file as an external library of the project in Eclipse.

In the Project > Properties > PyDev - PYTONPATH > External Libraries > Add zip/jar/egg

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top