sml2h3 / ddddocr

带带弟弟 通用验证码识别OCR pypi版
https://ddddocr.com
MIT License
8.96k stars 1.64k forks source link

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' #142

Closed JackieChan14 closed 7 months ago

JackieChan14 commented 9 months ago

Pillow库在10.0.0以上版本已经弃用了ANTIALIAS属性,最新版1.4.8的ddddocr也没有更新,目前只能采用降级Pillow到9.5.0的方式解决,希望能够早点适配10.0.0以上的Pillow

ZyangLee commented 8 months ago

将报错文件中的所有ANTIALIAS改成LANCZOS就可以了

alfred-hong commented 8 months ago

ANTIALIAS was removed in Pillow 10.0.0 (after being deprecated through many previous versions). Now you need to use PIL.Image.LANCZOS or PIL.Image.Resampling.LANCZOS. (This is the exact same algorithm that ANTIALIAS referred to, you just can no longer access it through the name ANTIALIAS.)

等待更新吧

yyanchu commented 8 months ago

pip install Pillow==9.5.0

TransparentLC commented 8 months ago

如果不想降级 PIL 也不想修改 ddddocr 的源代码的话,可以在 import ddddocr 前面加上:

from PIL import Image
if not hasattr(Image, 'ANTIALIAS'):
    setattr(Image, 'ANTIALIAS', Image.LANCZOS)

原理应该很清晰了(

sml2h3 commented 7 months ago

如果不想降级 PIL 也不想修改 ddddocr 的源代码的话,可以在 import ddddocr 前面加上:

from PIL import Image
if not hasattr(Image, 'ANTIALIAS'):
    setattr(Image, 'ANTIALIAS', Image.LANCZOS)

原理应该很清晰了(

感谢建议,已采纳!

TransparentLC commented 7 months ago

如果不想降级 PIL 也不想修改 ddddocr 的源代码的话,可以在 import ddddocr 前面加上:

from PIL import Image
if not hasattr(Image, 'ANTIALIAS'):
    setattr(Image, 'ANTIALIAS', Image.LANCZOS)

原理应该很清晰了(

感谢建议,已采纳!

@sml2h3 这个方法属于 monkey patching,除非有特殊情况(比如不方便修改源代码)否则一般不建议这么操作。如果是更新 ddddocr 的源代码的话,还是应该改成使用 Image.LANCZOS 而不是直接 setattr

sml2h3 commented 7 months ago

如果不想降级 PIL 也不想修改 ddddocr 的源代码的话,可以在 import ddddocr 前面加上:

from PIL import Image
if not hasattr(Image, 'ANTIALIAS'):
    setattr(Image, 'ANTIALIAS', Image.LANCZOS)

原理应该很清晰了(

感谢建议,已采纳!

@sml2h3 这个方法属于 monkey patching,除非有特殊情况(比如不方便修改源代码)否则一般不建议这么操作。如果是更新 ddddocr 的源代码的话,还是应该改成使用 Image.LANCZOS 或者用 hasattr 来检测是否存在 Image.ANTIALIAS

好的哦,也算是我偷懒了,下次更新的时候恢复正常做法

jianhua1996 commented 4 months ago

如果不想降级 PIL 也不想修改 ddddocr 的源代码的话,可以在 import ddddocr 前面加上:

from PIL import Image
if not hasattr(Image, 'ANTIALIAS'):
    setattr(Image, 'ANTIALIAS', Image.LANCZOS)

原理应该很清晰了(

感谢建议,已采纳!

@sml2h3 这个方法属于 monkey patching,除非有特殊情况(比如不方便修改源代码)否则一般不建议这么操作。如果是更新 ddddocr 的源代码的话,还是应该改成使用 Image.LANCZOS 或者用 hasattr 来检测是否存在 Image.ANTIALIAS

好的哦,也算是我偷懒了,下次更新的时候恢复正常做法

请问这个问题是还没有更改吗,使用中还是会报这个错误