- ModuleNotFoundErrorModuleNotFoundError: No module named 'PIL'
Fix "No module named 'PIL'": install Pillow into the interpreter that runs your code. Tested commands for venv, Windows, macOS, Linux, conda, Jupyter, Docker.
- AttributeErrorAttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Image.ANTIALIAS was removed in Pillow 10. Use Image.LANCZOS (the same filter on every version), patch old libraries, and see why pinning Pillow<10 fails.
- AttributeErrorAttributeError: 'ImageDraw' object has no attribute 'textsize'
textsize() and getsize() were removed in Pillow 10. Replace them with textbbox() or textlength(): a drop-in helper, the centring fix and real measurements.
- UnidentifiedImageErrorPIL.UnidentifiedImageError: cannot identify image file
Why Pillow says "cannot identify image file": HTML saved as .jpg, empty downloads, unrewound BytesIO, HEIC, SVG. Each reproduced, with a diagnostic script.
- OSErrorOSError: cannot open resource (ImageFont.truetype)
ImageFont.truetype() raises "cannot open resource" when it cannot find the font. Where Pillow looks on Windows, macOS and Linux, and a loader with fallback.
- TypeErrorTypeError: Cannot handle this data type: (1, 1, 3), <f4
fromarray raises "Cannot handle this data type: (1, 1, 3), <f4" when no Pillow mode fits the dtype or shape. How to read it, and the fix for each array type.
- OSErrorOSError: cannot write mode F as JPEG (and P, LA, I;16, CMYK…)
"cannot write mode X as JPEG" means the format cannot store that mode. A tested table of modes per format, and the right conversion for RGBA, P, F, I;16, CMYK.
- OSErrorOSError: image file is truncated (N bytes not processed)
"image file is truncated" means the file ends early. Why open() works but load() fails, how to find bad files, and when LOAD_TRUNCATED_IMAGES is safe.
- DecompressionBombWarningDecompressionBombWarning: Image size exceeds limit, could be decompression bomb DOS attack
Pillow warns above 89,478,485 pixels and raises DecompressionBombError above twice that. What it protects, raising it safely, and handling huge images.
- TypeErrorTypeError: Image data of dtype object cannot be converted to float
matplotlib imshow() raises "Image data of dtype object cannot be converted to float" when given None, a path or a list instead of image data. Causes and fixes.
- TypeErrorTypeError: 'tuple' object does not support item assignment
Why changing a Pillow pixel's channel or img.size raises "'tuple' object does not support item assignment", the fixes, and the NumPy read-only array version.
- AttributeErrorscipy.misc has no attribute imread (or imresize, imsave, toimage)
scipy.misc.imread, imresize, imsave and toimage were removed. Drop-in replacements with Pillow and imageio, and the differences that silently change results.
- AttributeError / ImportErrormodule 'PIL' has no attribute 'Image', and other import mix-ups
Fix "module 'PIL' has no attribute 'Image'", "No module named 'Image'" and "cannot import name 'ImageTk'": each error reproduced, with the fix.
- ImportErrorImportError: cannot import name '_imaging' from 'PIL'
Pillow's compiled core failed to load: '_imaging', DLL load failed, built for another Pillow, missing libraries in Lambda or Docker, decoder jpeg not available.
- AttributeErrorAttributeError: module 'PIL.Image' has no attribute 'Resampling'
Image.Resampling and the other enums arrived in Pillow 9.1. Reproduced on 9.0.1, with the upgrade, a constant that works everywhere, and what pins old Pillow.
- Django fields.E210Cannot use ImageField because Pillow is not installed
Django's fields.E210, reproduced: Pillow missing, installed in another environment, or installed but broken (Django hides the real error). Tested on Django 6.
Quick answers
Short fixes for errors that do not need a full page.
Out of memory processing large images
Cause: Large images are decoded fully into RAM before processing.
Fix: Use JPEG draft mode, downscale early, or process in tiles.
img = Image.open("huge.jpg")
img.draft("RGB", (800, 600)) # JPEG only
img.load()Image appears rotated after opening
Cause: Cameras store rotation in the EXIF Orientation tag; Pillow does not auto-rotate on open.
Fix: Apply the EXIF transpose.
from PIL import ImageOps img = ImageOps.exif_transpose(img)
images do not match
Cause: ImageChops operations require both images to have identical size and mode.
Fix: Normalise size and mode before combining.
b = b.convert(a.mode).resize(a.size) result = ImageChops.difference(a, b)
'Image' object is not subscriptable / cannot slice
Cause: Treating a Pillow Image like a NumPy array.
Fix: Convert explicitly, or use getpixel().
import numpy as np arr = np.array(img) # to array crop = img.crop((0, 0, 100, 100))
Permission denied when saving
Cause: The output file is open in another program, or the target directory is not writable.
Fix: Close the file, or write to a different path / ensure the directory exists.
import os
os.makedirs("out", exist_ok=True)
img.save("out/result.png")cannot import name 'ImageDraw' from 'PIL'
Cause: Usually a file or folder named PIL (e.g. PIL.py) in your project is shadowing the real package; the error message shows its path. Also seen with a broken or partial install.
Fix: Rename your PIL.py, or reinstall Pillow. Then import submodules explicitly.
from PIL import Image, ImageDraw, ImageFont
No error matches. Try fewer words, or send us the message and we will write it up.