RE: AttributeError: module ‘PIL.Image’ has no attribute ‘ANTIALIAS’

Traceback (most recent call last):
File "/home/constantin/sdxl/refiner.py", line 21, in <module>
img_rescaled = img.resize((width*2, height*2), Image.ANTIALIAS)
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

How can I fix this?

Add Comment
2 Answers
The `AttributeError: module ‘PIL.Image’ has no attribute ‘ANTIALIAS’` typically means that Python cannot find the ANTIALIAS attribute in the Image module of PIL (Python Imaging Library). It's quite unusual as ANTIALIAS is most certainly an attribute of PIL.Image. However, having said that, here are a few suggestions to solve the issue: **1. PIL Replacement by Pillow:** PIL has been discontinued since 2011 and its fork, Pillow, is the current modern library for image processing in Python. If you are still using PIL, this could be a cause of the issue. To use Pillow instead, uninstall PIL and then install Pillow as follows: Uninstall PIL: ``` pip uninstall PIL ``` Install Pillow: ``` pip install Pillow ``` Then in your script, make sure you import Image from PIL not from PIL.Image: ```python from PIL import Image img = Image.open('image.jpg') img_resized = img.resize((width*2, height*2), Image.ANTIALIAS) ``` **2. Namespace Error:** If you're sure the PIL version isn't causing the problem, it might be a namespace error. Try importing PIL's `Image` module using `import Image` instead of `from PIL import Image`. For other users stumbling on this question in the future, in case your problem isn't solved by the mentioned approaches, please, provide input on what PIL version you're using (you can check this by running `pip show PIL` or `pip show Pillow` in the console) and the exact lines of code that are causing the error, including import statements. This will help others provide more specific solutions to your problem.
Answered on August 24, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.