AttributeError: module 'PIL.图像文件"没有属性"图像文件">
我已经使用命令"pip 安装枕头"安装了 PIL
From PIL import Image
sourceFileName = "source.png"
Avatar= Image.open(sourceFileName)
File "d:/sourcecode/test.py", line 3, in <module>
Avatar= Image.open(sourceFileName)
File "C:**Python37-32libsite-packagesPILImage.py", line 2663, in open
Preinit()
File "C:**Python37-32libsite-packagesPILImage.py", line 381, in preinit
From . import BmpImagePlugin
File "C:**Python37-32libsite-packagesPILBmpImagePlugin.py", line 61, in <module>
Class BmpImageFile(ImageFile.ImageFile):
AttributeError: module 'PIL.ImageFile' has no attribute 'ImageFile'
您可以按如下方式导入图像文件:
from PIL import Image, ImageFile
sourceFileName = "source.png"
avatar = Image.open(sourceFileName)