4

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?

4 Answers 4

3

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

2 Comments

I'm sure, if it wouldn't be it would fail to run. I suspect that this bug is the cause sourceforge.net/tracker/…
does the proposed solution work? because how the interpreter runs has nothing to do how it is configured for eclipse/pydev. pydev requires configuration only for itself. f.e. the autosuggestion-features. if you execute the current script through the pydev-ui, the real interpreter is used.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.