我目前正在学习 python 及其模块/包。现在,我正在尝试摆弄枕头模块。但是,我什至似乎无法导入它。每当我运行以下命令时:
from PIL import _imaging as core
# from PIL import Image
img = core.open("elzero-pillow.png")
我收到一条错误消息,指出:
from PIL import _imaging 作为核心
导入错误:无法从“PIL”导入名称“_imaging”
我尝试了文档中所有可能的组合,但没有结果。非常感谢您的帮助。
您当前的代码实际上会引发此错误
AttributeError: module 'PIL._imaging' has no attribute 'open'
。我不知道你为什么注释掉 from PIL import Image
因为这就是我猜你需要的。试试这个:
from PIL import Image as core
img = core.open("C:\\Users\\John Piper\\Desktop\\mail.png")
您可以检查图像对象的详细信息,也可以使用以下代码显示图像:
print(img.format, img.size, img.mode) # Examine details of your image object
img.show() # Display your image
有关如何对图像执行其他操作的更多信息,请参阅 https://pillow.readthedocs.io/en/stable/handbook/tutorial.html。