Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ArtDoctor opened this issue Jul 9, 2023 · 24 comments
Open

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

ArtDoctor opened this issue Jul 9, 2023 · 24 comments

Comments

@ArtDoctor
Copy link

When I try to use easyocr on any image, I get this error:
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

According to (https://stackoverflow.com/questions/76616042/attributeerror-module-pil-image-has-no-attribute-antialias), new version of PIL (10.0.0) has no ANTIALIAS, as it's deprecated.

Full error:

File "...", line 8, in convert_img_to_text
result = reader.readtext(img_path)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\venv\Lib\site-packages\easyocr\easyocr.py", line 464, in readtext
result = self.recognize(img_cv_grey, horizontal_list, free_list,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\venv\Lib\site-packages\easyocr\easyocr.py", line 383, in recognize
image_list, max_width = get_image_list(h_list, f_list, img_cv_grey, model_height = imgH)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\venv\Lib\site-packages\easyocr\utils.py", line 613, in get_image_list
crop_img,ratio = compute_ratio_and_resize(crop_img,width,height,model_height)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\venv\Lib\site-packages\easyocr\utils.py", line 576, in compute_ratio_and_resize
img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.ANTIALIAS)

@ArtDoctor
Copy link
Author

Some update: downgrading Pillow to 9.5.0 fixes this issue, but I think it will be a good idea to also change the ANTIALIAS parameter in the easyocr\utils.py too.

@Rockyisnoteasy
Copy link

I met the same error just now, now i ll try your method

@Rockyisnoteasy
Copy link

It works,very thanks

@SabahatAnsari
Copy link

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

@ArtDoctor
Copy link
Author

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal:
pip install --force-reinstall -v "Pillow==9.5.0"
After this it should work.

@Yingrjimsch
Copy link

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

This works thanks I've got the issue right now but it would be great to make it compatible with newer versions.
It seems like PIL.Image.LANCZOS or PIL.Image.Resampling.LANCZOS need to be used to achieve the same thing.

@SabahatAnsari
Copy link

Thank You

@silence0618
Copy link

pip install --force-reinstall -v "Pillow==9.5.0"

It works for me. Thanks

cokelaer added a commit to sequana/sequana that referenced this issue Jul 28, 2023
PIL fails on RTD due to AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' . Based on JaidedAI/EasyOCR#1077 let us try to add pillow with <=9.5.0 . Pillow is not part of RTD from aug 2023 os good to add it here anyway
cokelaer added a commit to sequana/sequana that referenced this issue Jul 29, 2023
Update .readthedocs.yml

Update .readthedocs.yml

Update .readthedocs.yml

Update .readthedocs.yml

Update .readthedocs.yml

add pillow <=9.5.0

PIL fails on RTD due to AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' . Based on JaidedAI/EasyOCR#1077 let us try to add pillow with <=9.5.0 . Pillow is not part of RTD from aug 2023 os good to add it here anyway

Update requirements.txt

Update .readthedocs.yml

Update requirements.txt
@pratyush-1966
Copy link

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

@Yingrjimsch
Copy link

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

Use PILOW==9.5.0 as workaround. That worked for me.

@dekwidap
Copy link

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

Thankyou. Currently using Pillow 10.0.0. Then downgrade. It's work.

@ozgurmsc
Copy link

ozgurmsc commented Aug 26, 2023

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

you just saved my life thank you

@davidearlyoung
Copy link

Having the same issue. I'll give the PIL older version a try. I agree that easyocr should be adjusted for newer PIL versions. Or at least give people a heads up at installation documentation.

@archywillhe
Copy link

This issue is fixed in the master branch.
You can install the master branch via:
pip install git+https://github.com/JaidedAI/EasyOCR.git

@davidearlyoung
Copy link

Back installing worked for me. As well as installing from the the git master as archywillh mentioned worked for me as well. Thank you archywillhe for that info by the way. Additional question. If you don't mind me asking so I can better assist myself in the future, where did you find the info that the master branch had a fix for this?

@tuha1994
Copy link

tuha1994 commented Sep 7, 2023

Pillow to 9.5.0

working with me,thanks you

@SunYuhe26862
Copy link

I've had this problem for a long time, thanks for your help

@patrickmappedin
Copy link

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

@wtigga
Copy link

wtigga commented Oct 25, 2023

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Much better than downgrading PIL. Thank you!

@Rebeque
Copy link

Rebeque commented Nov 10, 2023

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Heroic thanks!

@NasrCH
Copy link

NasrCH commented Nov 22, 2023

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Thanks ! you saved my day

@crisstang
Copy link

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Its a good idea!!!

@pranith7
Copy link

Hey @patrickmappedin,
I have tried both the approaches
a. Downgrading pillow
b. PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

but i am getting error like Illegal instruction
You can read my post for more info

@ShariShah1234
Copy link

Some update: downgrading Pillow to 9.5.0 fixes this issue, but I think it will be a good idea to also change the ANTIALIAS parameter in the easyocr\utils.py too.

its work thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests