使用from-import-as时,pydev导致错误 [英] Unresolved import error with pydev while using from-import-as
问题描述
在使用PyDev的Eclipse中,我得到一个未解析的导入:pilImage
错误,同时具有此代码。
In Eclipse with PyDev I get an Unresolved import: pilImage
error while having this code.
从PyDev或Shell内部执行代码时,代码工作得很好,但是IDE将高亮度显示为错误。
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
我如何解决问题?
推荐答案
我认为这可能是一个误会关于如何使用PIL ...
I think it may be a bit of a misunderstanding on how PIL should be used...
PIL有一个相当不寻常的打包,其中PIL库被添加到PYTHONPATH(而不是包含它的目录),因此,如果您使用easy-install进行安装,则会执行以下操作:
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
所以,应该实际完成的导入是: import Image作为pilImage (即:导入中的PIL不存在)。
So, the import that should actually be done is: import Image as pilImage (i.e.: no from PIL in the import).
是导入应该如何: http://effbot.org/imagingbook/introduction.htm
在这种情况下,添加到PYTHONPATH的目录应该是:/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg
And in this case, the directory added to the PYTHONPATH should be: "/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg"
请注意,如果您重命名目录 /Lib/site-packages/PIL-1.1.7-py2.6-win32.egg 到 / Lib / site-packages / PIL ,并在PYTHONPATH中留下 / Lib / site-packages / (在这种情况下,您仍然需要去PyDev解释器配置,只需按下应用程序,以便它发现一个新的PIL包被添加到PYTHONPATH - 注意,在这种情况下/ lib / site-packages / PIL不应该添加到PYTHONPATH )
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)
这篇关于使用from-import-as时,pydev导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!