0

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?

Levon
  • 138,105
  • 33
  • 200
  • 191
Jen Luk
  • 3
  • 3

2 Answers2

1

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.

Community
  • 1
  • 1
Adam Morris
  • 8,265
  • 12
  • 45
  • 68
  • Hi, thanks for answering. I did try what you suggested, but unfortunately, it did not work. The same error about not being able to find the module still comes up in response. – Jen Luk Jul 25 '12 at 17:18
  • @JenLuk - What OS are you on? – Adam Morris Jul 26 '12 at 00:22
  • @JenLuk - does it work when you start a pydev interpreter and import it from there? Also... I'm assuming your project is set as a pyDev project... (right click on the project -> PyDev -> "Set as PyDev Project" if it's not) – Adam Morris Jul 26 '12 at 13:19
0

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

jrichalot
  • 59
  • 1
  • 7