简体   繁体   中英

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:

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:

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? (see: https://www.pydev.org/manual_101_interpreter.html for more details)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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