Unresolved import error with pydev when using from-import-as

In Eclipse with PyDev, I get an Unresolved import: pilImage when using this code.

The code works well when executed inside PyDev or the shell, but the IDE strongly illuminates me as an error.

 from PIL import Image as pilImage # do something with pilImage 

How can i solve the problem?

+4
source share
4 answers

I think this may be a bit of a misunderstanding in how to use PIL ...

PIL has a rather unusual packaging in which the PIL library is added to PYTHONPATH (and not to the directory containing it), so if you install using a simple installation, it will do something like:

 /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 actually needs to be done is: import the image as pilImage (i.e.: not in the PIL when importing).

Link confirming that this is how import should be: http://effbot.org/imagingbook/introduction.htm

And in this case, the directory added to PYTHONPATH should be: "/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg"

Please note that your import may work if you renamed the /Lib/site-packages/PIL-1.1.7-py2.6-win32.egg directory to / lib / site- packages / PIL and just leave / lib / site- packages / in PYTHONPATH (in this case, you still need to go to setting up the PyDev interpreter and just click "apply" so that it finds that the new PIL package has been added to the PYTHONPATH note , which in this case is / Lib / site -packages / PIL should NOT be added to PYTHONPATH )

+3
source

Did you install PIL as an egg after installing PyDev? If so, PyDev will not know this. Remove and re-add the interpreter to fix this. See this SO question for more details.

+1
source

Are you sure that your interpreter configured by PyDev knows the PIL package and its contents? If you configured the PyDev Python interpreter before installing the PIL packages, it knows nothing about it.

0
source

Sometimes PyDev requires a restart of Eclipse in order to fix an incorrect error message. This often occurs when a user writes an import before adding a module.

0
source

Source: https://habr.com/ru/post/1382241/


All Articles