AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
im = im.resize((320, 240), Image.ANTIALIAS)
im = im.resize((320, 240), Image.Resampling.LANCZOS)
Pillow 9.1 grouped the loose constants into enums and marked the old spellings as deprecated. Pillow 10, released in July 2023, removed them. Any tutorial, book or answer written before 2022 uses the old name, which is why this error turns up so often.
ANTIALIAS was never a separate algorithm. It was an alias for the Lanczos filter, so the replacement gives you identical output.
| Old | New |
|---|---|
Image.ANTIALIAS | Image.Resampling.LANCZOS |
Image.LINEAR | Image.Resampling.BILINEAR |
Image.CUBIC | Image.Resampling.BICUBIC |
Image.FLIP_LEFT_RIGHT | Image.Transpose.FLIP_LEFT_RIGHT |
Image.ROTATE_90 | Image.Transpose.ROTATE_90 |
When the call lives inside a dependency you do not control, pin Pillow below 10 while you wait for an update:
pip install "Pillow<10"
Treat that as temporary. You are holding back security fixes in image decoders, which is not a good place to stay.
If you are making a thumbnail, you do not need the constant at all. thumbnail already uses a good filter and keeps the aspect ratio:
im.thumbnail((320, 240))
The resampling comparison shows what each filter does.
The PIL to Pillow converter finds most of these automatically, and the other error pages cover the rest.