AttributeError: module ‘PIL.Image‘ has no attribute ‘ANTIALIAS‘ | 您所在的位置:网站首页 › gta51·9版本 › AttributeError: module ‘PIL.Image‘ has no attribute ‘ANTIALIAS‘ |
在使用ddddocr进行图片识别时,报错了: AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'我使用的是Python 3.11,查看一下pillow的版本: print(PIL.__version__) 10.0.0到处百度也没找到原因,最后,在pillow的release notes中找到了问题:
原来是在pillow的10.0.0版本中,ANTIALIAS方法被删除了,使用新的方法即可: Image.LANCZOS Image.Resampling.LANCZOS解决办法: 方案一,修改ddddocr的_init_.py文件,将其中的ANTIALIAS替换为新方法: # image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.ANTIALIAS).convert('L') image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.LANCZOS).convert('L')方案二,降级Pillow的版本,比如使用9.5.0版本 先卸载,再重新安装 pip uninstall -y Pillow pip install Pillow==9.5.0两种方案都亲测可用 |
CopyRight 2018-2019 实验室设备网 版权所有 |