Home / Products / PIL

PIL is now Pillow

If you followed a link here looking for the Python Imaging Library, this page is the short version of what happened and what to install instead.

Install Pillow, import PIL. That is not a typo, and it trips up nearly everybody the first time.
python -m pip install Pillow
from PIL import Image

im = Image.open("photo.jpg")
print(im.format, im.size, im.mode)
im.thumbnail((200, 200))
im.save("thumb.png")

What happened to PIL

The Python Imaging Library was written by Fredrik Lundh and released through PythonWare. The last release was 1.1.7 in 2011. It was never ported to Python 3.

Pillow began in 2010 as a fork to make PIL installable with modern packaging, and became the maintained continuation of the project. It keeps the same import name, so from PIL import Image works in both. That choice is why twenty year old tutorials still look almost right, and also why so much old code fails in confusing ways rather than obviously.

Why old code breaks

Three kinds of change account for nearly every failure.

The modules moved into the package

Old code did import Image. That has not worked since PIL 1.1.6, and needs to be from PIL import Image.

The constants moved into enums

Pillow 9.1 grouped the loose constants into enums, and Pillow 10 removed the old names. Image.ANTIALIAS is the one everybody hits.

Old nameUse this now
Image.ANTIALIASImage.Resampling.LANCZOS
Image.CUBICImage.Resampling.BICUBIC
Image.LINEARImage.Resampling.BILINEAR
Image.FLIP_LEFT_RIGHTImage.Transpose.FLIP_LEFT_RIGHT
Image.ROTATE_90Image.Transpose.ROTATE_90
Image.AFFINEImage.Transform.AFFINE
Image.ADAPTIVEImage.Palette.ADAPTIVE
Image.FLOYDSTEINBERGImage.Dither.FLOYDSTEINBERG

Some methods were renamed or removed

Old callUse this now
im.tostring()im.tobytes()
Image.fromstring()Image.frombytes()
draw.textsize(text, font)draw.textbbox((0, 0), text, font=font)
font.getsize(text)font.getbbox(text) or font.getlength(text)
im.offset(x, y)ImageChops.offset(im, x, y)
PIL.VERSIONPIL.__version__

The converter tool applies all of this to a block of code and tells you what it changed.

Things that did not change

Most of the library is the same. Image.open, save, crop, paste, convert, split, merge, the band and mode system, the coordinate system with the origin at the top left, and the lazy loading behaviour all work as they always did. A PIL era book is still a reasonable way to learn the model, as long as you translate the names above as you read.

Where to go next