Reputation: 170310
In Eclipse with PyDev I get an Unresolved import: pilImage
error while having this code.
The code works well when executed from inside PyDev or shell, but the IDE is high-lighting me this as an error.
from PIL import Image as pilImage
# do something with pilImage
How can I solve the problem?
Upvotes: 4
Views: 2488
Reputation: 25332
I think it may be a bit of a misunderstanding on how PIL should be used...
PIL has a rather uncommon packaging, in which the PIL library is added to the PYTHONPATH (and not the directory containing it), so, if you install with easy-install, it'll do something as:
/Lib
/Lib/site-packages
/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg
/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg/Image.py
So, the import that should actually be done is: import Image as pilImage (i.e.: no from PIL in the import).
A reference backing up that this is how the import should be: http://effbot.org/imagingbook/introduction.htm
And in this case, the directory added to the PYTHONPATH should be: "/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg"
Note that your import could work if you renamed the directory /Lib/site-packages/PIL-1.1.7-py2.6-win32.egg to /Lib/site-packages/PIL and just left /Lib/site-packages/ in the PYTHONPATH (in which case you still would need to go to the PyDev interpreter configuration and just press apply so that it finds out that a new PIL package was added to the PYTHONPATH -- note that in this case /Lib/site-packages/PIL should NOT be added to the PYTHONPATH)
Upvotes: 3
Reputation: 2362
Sometimes PyDev requires you to restart Eclipse in order to correct the wrong error message. It's often caused when a user writes the import before adding the module.
Upvotes: 0
Reputation: 3494
Did you install PIL as an egg after installing PyDev? If so, PyDev won't know it's there. Remove and re-add the interpreter to fix this. See this SO question for more.
Upvotes: 1
Reputation: 121
Are you sure that your PyDev-configured interpreter knows the PIL-package and it's contents? If you configured your PyDev Python-interpreter before you installed the PIL-packages, it doesn't know anything about it.
Upvotes: 0