Install the package called Pillow using the same interpreter that runs your code, then import it as PIL:
python -m pip install --upgrade Pillow
On Windows use py -m pip install --upgrade Pillow. Never run pip install PIL: that package does not exist on PyPI.
What the error looks like
We reproduced it by running a one-line script in a fresh virtual environment that does not have Pillow:
from PIL import Image
img = Image.open("photo.jpg")
Traceback (most recent call last):
File "example.py", line 1, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
The name is confusing for a reason. The original Python Imaging Library (PIL) stopped being developed in 2011 and never
supported Python 3. Pillow is the maintained fork. It is installed as Pillow but keeps the old import name
PIL so existing code keeps working.
Cause 1: Pillow is installed, but for a different Python
This is the most common cause, especially if you are sure you already installed Pillow. Your machine can have several
Pythons: the system one, one from python.org or Homebrew, a conda base, and one per virtual environment. A bare
pip command installs into whichever Python that particular pip belongs to, which is not necessarily
the one your editor or terminal runs.
Ask the Python that fails which interpreter it is. Add this at the top of the failing script, or run it in the same notebook or terminal:
import sys
print(sys.executable) # the interpreter running this code
print(sys.version.split()[0])
/home/you/.venv/bin/python
3.13.16
Then ask pip which Python it installs into:
python -m pip --version
pip 26.2.1 from /home/you/.venv/lib/python3.13/site-packages/pip (python 3.13)
If the two paths point to different Pythons, you found the problem. The cure is to always invoke pip through the interpreter
itself, python -m pip, so the install goes where the code runs. If sys.executable printed a path you
did not expect, use that exact path: /that/path/python -m pip install Pillow.
Cause 2: Pillow is simply not installed
python -m pip install --upgrade Pillow
Then pick the line for your setup:
| Setup | Command or action |
|---|---|
| Virtual environment (venv) | Activate it first (source .venv/bin/activate, or .venv\Scripts\activate on Windows), then python -m pip install Pillow. |
| Windows, python.org installer | py -m pip install Pillow. The py launcher picks the newest installed Python. Add a version to target another one, e.g. py -3.12 -m pip install Pillow. |
| macOS (python.org or Homebrew) | python3 -m pip install Pillow. Plain python may not exist on macOS. With Homebrew Python, install inside a venv (see the next row). |
Debian, Ubuntu, Homebrew: error: externally-managed-environment | Your OS protects its own Python (PEP 668). Create a venv: python3 -m venv .venv && . .venv/bin/activate && python -m pip install Pillow. Or, for the system Python only, sudo apt install python3-pil. |
| Anaconda / Miniconda | conda install -c conda-forge pillow in the activated environment. Avoid mixing conda and pip installs of Pillow in one environment. |
| Jupyter / JupyterLab | Run %pip install Pillow in a cell. The %pip magic installs into the kernel's Python. Then restart the kernel. |
| Google Colab | Pillow is preinstalled. If you see this error, a previous cell probably uninstalled it. Run %pip install Pillow and restart the runtime. |
| VS Code | Command Palette, then Python: Select Interpreter, then pick the environment where Pillow is installed (or install into the one shown in the status bar). |
| PyCharm | Settings, Project, Python Interpreter: check the selected interpreter, then add Pillow with the + button. |
| Docker | Add RUN python -m pip install --no-cache-dir Pillow to the Dockerfile. Pillow ships prebuilt wheels for the official python:3.x-slim images, so no compiler is needed. |
Cause 3: you ran pip install PIL
There is no installable package called PIL on PyPI. This is what pip prints when you try:
python -m pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL
Install Pillow instead. Also uninstall any look-alike packages you may have tried along the way (for example
python -m pip uninstall image), since they do not provide PIL.
Cause 4: old code that imports Image directly
Scripts written for PIL 1.1.x on Python 2 often used import Image instead of from PIL import Image.
Pillow never supported that style, so the error mentions Image rather than PIL:
import Image # PIL 1.1.x style, from the Python 2 era
img = Image.open("photo.jpg")
ModuleNotFoundError: No module named 'Image'
Change the import. The rest of the old code usually works unchanged:
from PIL import Image
img = Image.open("photo.jpg")
print(img.format, img.size)
JPEG (1600, 1067)
The same goes for import ImageDraw, import ImageFont and friends: use from PIL import ImageDraw, ImageFont.
Related: cannot import name 'Image' from 'PIL'
If Pillow is installed but you get an ImportError that names a file in your project, a file or folder
called PIL is hiding the real library. We reproduced it with an empty PIL.py next to the script:
from PIL import Image
ImportError: cannot import name 'Image' from 'PIL' (/home/you/project/PIL.py)
The path in brackets is the culprit. Written as import PIL.Image, the same problem produces a different message:
import PIL.Image
ModuleNotFoundError: No module named 'PIL.Image'; 'PIL' is not a package
Rename or delete your PIL.py (and any __pycache__/PIL.*.pyc next to it). Avoid naming your own
files after libraries you import, such as PIL.py, pillow.py or image.py.
Confirm the fix
import PIL
from PIL import Image
print(PIL.__version__)
print(PIL.__file__)
12.3.0
/home/you/.venv/lib/python3.13/site-packages/PIL/__init__.py
If this prints a version and a path inside the environment you expect, you are done. For a full report of which image
formats and libraries your install supports, run python -m PIL --report.
Still failing after installing? If the error changed to cannot import name '_imaging' from 'PIL',
the compiled part of Pillow does not match your Python (often after upgrading Python, or copying a venv between machines).
Reinstall it cleanly: python -m pip uninstall -y Pillow then python -m pip install --no-cache-dir Pillow.
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.