Home / Errors / no-module-named-pil

No module named PIL

The package is called Pillow and the import is called PIL. Install Pillow, import PIL.

ModuleNotFoundError: No module named 'PIL'

The fix

python -m pip install Pillow

Not pip install PIL, which installs nothing useful, and not pip install pil.

Why the names differ

PIL was the original library and stopped in 2011. Pillow forked it and kept the same import name so existing code would keep working. The distribution is Pillow, the package is PIL. That mismatch has confused people for fifteen years.

If pip says it is already installed

You almost certainly have more than one Python, and you installed into a different one. Use the interpreter itself to install:

python -m pip install Pillow

import sys
print(sys.executable)

Run that print inside the program that fails. If it does not match the Python you installed into, that is your answer.

In a virtual environment

python -m venv .venv
source .venv/bin/activate
python -m pip install Pillow

On Windows the activate line is .venv\Scripts\activate. Your editor may also need telling which interpreter to use, which is a common cause of code that runs in the terminal but not in the IDE.

In notebooks

%pip install Pillow

The magic installs into the kernel actually running the notebook, which a plain shell command does not always do.

Still stuck

The PIL to Pillow converter finds most of these automatically, and the other error pages cover the rest.