问题遇到的现象和发生背景
正在学习python的pillow模块,使用的python版本是3.10。
通过pip3 安装了最新版本的pillow9.2.0,但是在调用Image.crop方法裁剪图片时,PyCharm总是报错。
问题相关代码,请勿粘贴截图
from PIL import Image
from pathlib import Path
import os
p1 = Path('d:/python/test')
os.chdir(p1)
image_file = Image.open('zophie.png')
print(image_file.size)
crop_image = Image.crop(1,1,10,10)
image_file.save('crop_image_file.png')
运行结果及报错内容
Traceback (most recent call last):
File "D:\Python\工作自动化\test.py", line 10, in <module>
crop_image = Image.crop(1,1,10,10)
File "C:\Users\idhx\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 76, in __getattr__
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
AttributeError: module 'PIL.Image' has no attribute 'crop'
(816, 1088)
我的解答思路和尝试过的方法
尝试卸载后重新安装其他几个版本的pillow,但也是同样的问题
我想要达到的结果
请问有遇到类似问题的吗,望指点解决办法,谢谢!