Attributeerror: Module 'Pil. Image' Has No Attribute 'Antialias'

Attributeerror: Module 'Pil. Image' Has No Attribute 'Antialias'
  • Trying to have images in my Tkinter GUI, hence using PIL.
  • Image.ANTIALAIS is not working, however Image.BILINEAR works

Here's some sample code:

import tkinter as tk
from PIL import Image, ImageTk

window = tk.Tk()

image = Image.open(r"VC.png")
image = image.resize((20, 20), Image.ANTIALIAS)

tk_image = ImageTk.PhotoImage(image)

image_label = tk.Label(window, image=tk_image)
image_label.pack()

window.mainloop()

Here's the error:

Traceback (most recent call last):
  File "<module1>", line 19, in <module>
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
  • Tried reinstalling pip AND Pillow. Didn't work.
  • Asked Chat-GPT about this, advised me to upgrade to Pillow's latest ver. I am on the latest ver (10.0.0)
4

7 Answers

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.)

Reference: Pillow 10.0.0 release notes (with table of removed constants)


Simple code example:

import PIL
import numpy as np

# Gradient image with a sharp color boundary across the diagonal
large_arr = np.fromfunction(lambda x, y, z: (x+y)//(z+1),
                            (256, 256, 3)).astype(np.uint8)
large_img = PIL.Image.fromarray(large_arr)

# Resize it: PIL.Image.LANCZOS also works here
small_img = large_img.resize((128, 128), PIL.Image.Resampling.LANCZOS)
print(small_img.size)

large_img.show()
small_img.show()

6

In easyOcr, the following error appeared:

img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.ANTIALIAS)AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

What I did was the following:

pip uninstall Pillow
pip install Pillow==9.5.0

The problem must be with Pillow version 10.0.

1

The Problem is with pillow 10.0

Trying to uninstall pillow might give some errors.

Just put this in cmd pip install Pillow==9.5.0

1

Hacky way but worked:

In the utils.py file of easyOCR/Scripts, I replaced the ANTIALIAS with LANCZOS.

2

you can add below before your code as a quickly patch.

from PIL import Image as pil
from pkg_resources import parse_version
if parse_version(pil.__version__)>=parse_version('10.0.0'):
    Image.ANTIALIAS=Image.LANCZOS

ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use LANCZOS or Resampling.LANCZOS instead.

Downgrading using pip worked for me:

> pip3 install "Pillow<10.0.0"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.