为什么会出现“属性错误:模块 PIL 没有属性图像”,与安装的不同,并且代码是正确的

问题描述 投票:0回答:1

我是Python新手;我使用 pip 安装枕头包并尝试将其导入到我的代码中,但是当我运行代码时,它显示 AttributeError: module PIL has no attribute Image。 这是我的代码: 导入PIL

with PIL.Image.open("before1.jpg") as Im:
    Im.show()

我重新安装了python和pillow,但没有任何变化; 我尝试使用枕头 8.0.0 但没有任何变化; 以前我对 pytest 有同样的问题

python python-3.x module package attributeerror
1个回答
0
投票

你需要像这样导入它

from PIL import Image
这样它就可以找到Image类

© www.soinside.com 2019 - 2024. All rights reserved.