简体   繁体   English

为什么 PyDev 会标记导入错误但代码有效?

[英]Why does PyDev flag an import error but the code works?

Pillow has been added to the project.枕头已添加到项目中。 Here's the code:这是代码:

from PIL import Image, ImageFilter, ImageDraw, ImageFont
im = Image.open("someImage.jpg")
print(im.width, im.height, im.mode, im.format)  # Display
im.show(im)

Pillow is imported and the code runs fine, but PyDev gives the error: Pillow 被导入并且代码运行良好,但是 PyDev 给出了错误:

Unresolved import: Image
――――――――――――――――――――
Image Found at: foo

from PIL import Image, ImageFilter, ImageDraw, ImageFont

在此处输入图像描述

If I comment out the import statement, I get a different error:如果我注释掉 import 语句,我会得到一个不同的错误:

Traceback (most recent call last):
  File "C:\ImagePractice\foo.py", line 2, in <module>
    im = Image.open("someImage.jpg")
NameError: name 'Image' is not defined

@nicomp if you add PIL to the Forced Builtins in the interpreter you're using, does it work? @nicomp 如果您将PIL添加到您正在使用的解释器中的Forced Builtins中,它是否有效? (see: https://www.pydev.org/manual_101_interpreter.html for more details) (有关详细信息,请参阅: https://www.pydev.org/manual_101_interpreter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM