Search code examples
pythonpython-imaging-library

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


  • I am trying to have images in my Tkinter GUI, hence I am 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'
  • I tried reinstalling pip and Pillow. It didn't work.
  • I asked ChatGPT about this, and it advised me to upgrade to Pillow's latest version. I am on the latest version (10.0.0).

Solution

  • 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