Upgrade Pillow: python -m pip install --upgrade pillow. If you cannot upgrade (an old Python, or a
dependency that pins Pillow), write Image.LANCZOS instead of Image.Resampling.LANCZOS: the short
names work on every Pillow version, including the current one, without warnings.
The error, reproduced on Pillow 9.0.1
We keep a Python 3.10 environment with Pillow 9.0.1 to reproduce errors from old installs. The same script on the old and the current Pillow:
from PIL import Image
img = Image.open("photo.jpg")
small = img.resize((400, 267), Image.Resampling.LANCZOS)
print(small.size)
Traceback (most recent call last):
...
AttributeError: module 'PIL.Image' has no attribute 'Resampling'
from PIL import Image
img = Image.open("photo.jpg")
small = img.resize((400, 267), Image.Resampling.LANCZOS)
print(small.size)
(400, 267)
What changed in Pillow 9.1
Pillow 9.1 (April 2022) grouped its integer constants into enums: Image.Resampling,
Image.Transpose, Image.Dither, Image.Palette, Image.Quantize and
Image.Transform. On the older version, none of them exist:
import PIL
from PIL import Image
print("Pillow", PIL.__version__)
for name in ["Resampling", "Transpose", "Dither", "Palette", "Quantize", "Transform"]:
print(f" Image.{name:<11}", "yes" if hasattr(Image, name) else "missing")
print(" Image.LANCZOS ", Image.LANCZOS)
Pillow 9.0.1
Image.Resampling missing
Image.Transpose missing
Image.Dither missing
Image.Palette missing
Image.Quantize missing
Image.Transform missing
Image.LANCZOS 1
So the same error appears as has no attribute 'Transpose' for code that flips or rotates with
Image.Transpose.FLIP_LEFT_RIGHT, and so on. The fix is identical.
Find out why the old Pillow is there
Check the version the failing interpreter actually uses: python -c "import PIL; print(PIL.__version__)". If
upgrading does not stick, something pins it. python -m pip check lists conflicts, and if an installed package requires an older Pillow, pip names it in a
warning after the upgrade (… requires pillow<…, but you have pillow … which is incompatible). Common culprits
are old pinned requirements.txt files, conda environments that also contain an old Pillow, and Python 3.7 or
older, where Pillow 9.1 and later cannot be installed at all (the last release for 3.7 is 9.5, so even there
Resampling is available once you upgrade within the 9.x series).
Code that works on old and new Pillow
If you maintain a library or a script that must run everywhere, fall back to the short constants:
import PIL
from PIL import Image
try: # Pillow 9.1 and newer
LANCZOS = Image.Resampling.LANCZOS
FLIP_LR = Image.Transpose.FLIP_LEFT_RIGHT
except AttributeError: # older Pillow
LANCZOS = Image.LANCZOS
FLIP_LR = Image.FLIP_LEFT_RIGHT
img = Image.open("photo.jpg").resize((400, 267), LANCZOS).transpose(FLIP_LR)
print("Pillow", PIL.__version__, "->", img.size)
Pillow 9.0.1 -> (400, 267)
import PIL
from PIL import Image
try: # Pillow 9.1 and newer
LANCZOS = Image.Resampling.LANCZOS
FLIP_LR = Image.Transpose.FLIP_LEFT_RIGHT
except AttributeError: # older Pillow
LANCZOS = Image.LANCZOS
FLIP_LR = Image.FLIP_LEFT_RIGHT
img = Image.open("photo.jpg").resize((400, 267), LANCZOS).transpose(FLIP_LR)
print("Pillow", PIL.__version__, "->", img.size)
Pillow 12.3.0 -> (400, 267)
Simpler still: the short names (Image.LANCZOS, Image.FLIP_LEFT_RIGHT, …) were deprecated in 9.1
but the deprecation was reversed in 9.4, so on current Pillow they are ordinary aliases for the enum members. With warnings
turned into errors:
import warnings
from PIL import Image
warnings.simplefilter("error") # turn any deprecation warning into an error
print(Image.LANCZOS == Image.Resampling.LANCZOS, Image.FLIP_LEFT_RIGHT == Image.Transpose.FLIP_LEFT_RIGHT)
True True
The only names that are truly gone are the ones removed in Pillow 10, such as Image.ANTIALIAS; use
Image.LANCZOS for that.
Related
The outputs and images on this page are the real results of running every example with Pillow 12.3.0 on Python 3.13 (Linux) on 2026-10-15. Every example is also re-run automatically on macOS (Darwin 25.6.0, Pillow 12.3.0), Linux (Linux 6.17.0-1022-azure, Pillow 12.3.0), Windows (Windows 2025Server, Pillow 12.3.0); the line under each example shows the result per operating system. The DejaVu Sans font files sit next to each script so font examples behave the same everywhere. Sample photos: NASA/Sam Lott, public domain. Spotted something wrong? Tell us.