Use Pillow which is the "new" or the replacement of PIL, but has the same-named modules to preserve compatibility:

pip install pillow

Also, as suggested in the comments, maybe you are just using the wrong python binary, try to check if you're in/out of a virtual environment or check differences between python vs python3 vs python2 on your system:

python -m pip list
python2 -m pip list
python3 -m pip list
Answer from Peter Badida on Stack Overflow
🌐
PyPI
pypi.org › project › pillow
pillow · PyPI
pip install pillow Copy PIP instructions · Latest version · Released: Apr 1, 2026 · Python Imaging Library (fork) These details have been verified by PyPI · Changelog · Source · Repository · Stars: Forks: Open issues: Open PRs: aclark hugovk radarhere wiredfool ·
      » pip install pillow
    
Published   Apr 01, 2026
Version   12.2.0
Discussions

Import PIL does not work when Pillow is installed via pip
After installing, try importing in the interactive shell. In Windows terminal/command shell: py -m pip install Pillow py In the Python interactive shell, try, from PIL import Image exit() If this works, you are likely using a Python virtual environment in VS Code or working with a different version of Python. More on reddit.com
🌐 r/learnpython
12
2
February 19, 2023
python 3 - How am I supposed to install Pillow (not PIL) on Raspberry Pi OS? - Raspberry Pi Stack Exchange
I have a dependency on Pillow. Definitely not PIL because PIL lacks certain features - specifically ImageTk: ImportError: cannot import name 'ImageTk' from 'PIL'. pip install pillow returns error: externally-managed-environment and tells me to install using sudo apt install python3-pillow. More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
May 14, 2024
Probelms with Pillow: from PIL import image // modulenotfounderror no module named 'PIL'
Hello, I am creating a script that organizes PNG files into a single picture. However upon this line: from PIL import Image I get the following error: from PIL import Image ModuleNotFoundError: No module named ‘PIL’ I have newly installed PyCharm and Python 3.11.2 and installed pillow 9.4.0. ... More on discuss.python.org
🌐 discuss.python.org
13
0
March 21, 2023
How do I install Pillow (PIL) in Visual Studio?
Are you even aware that it is a library for Python? Do you know Python? What have you tried? Have you tried reading? A good thing to read would be: https://pillow.readthedocs.io/en/stable/installation/index.html More on reddit.com
🌐 r/learnprogramming
10
2
January 5, 2025
🌐
St. Olaf College
wp.stolaf.edu › it › installing-pil-pillow-cimage-on-windows-and-mac
Installing PIL/Pillow/cImage for Python on Windows and Mac – Information Technology
June 10, 2016 - sudo pip install pillow · pip3.4 install pillow · Download and install cImage · Download cimage.py · Navigate to https://github.com/bnmnetp/cImage · Click cImage.py, and click the button labeled Raw to see the contents of the file. Click File->Save Page As (Chrome & Firefox) or File->Save ...
🌐
Reddit
reddit.com › r/learnpython › import pil does not work when pillow is installed via pip
r/learnpython on Reddit: Import PIL does not work when Pillow is installed via pip
February 19, 2023 -

I'm coding a music player in python for learning and I see that PIL needs to be used for the "Logo.png" error (which I have the .png file for it). But the "Import PIL" doesn't work and spits out the "couldn't be resolved" error. Even though I have installed Pillow (and upgraded it). I'm using the Tkinter module for this project btw. Another thought I had was bypassing the PIL/Pillow module entirely and creating a more primitive version just to import images. But I haven't found any related instructions on getting python to recognize image files, especially for importing to projects.

🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-pil-on-windows
How to Install PIL on Windows? - GeeksforGeeks
July 23, 2025 - In this article, we will look into ... Open up the command prompt and use the below command to install the PIL package: pip install Pillow ·...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-install-pil-on-linux
How to Install PIL on Linux? | GeeksforGeeks
September 30, 2021 - Prerequisite:Python PIP or Ananconda (Depending upon your preference)For PIP Users: Open up the command prompt and use the below command to install the PIL package: pip install Pillow The follo
Top answer
1 of 7
32

The above solution did not work for me on Ubuntu 12.10 as libjpeg was not available in the repository.

What did end up working for me was:

sudo apt-get build-dep python-imaging
sudo apt-get install libjpeg62 libjpeg62-dev

If you get the error "You must put some 'source' URIs in your sources.list" then make sure that your /etc/apt/sources.list has deb-src entries which match your deb entries.

Then you must symlink the files from their actual location on your server to the location where PIL expects them.

32-bit version

sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/libz.so
sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib/libfreetype.so

64-bit version

sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/libz.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/libfreetype.so

Finally, pip install PIL

Success!


Update Sep 2014

Pillow is a more modern fork of PIL.

#jpeg support
sudo apt-get install libjpeg-dev
#tiff support
sudo apt-get install libtiff-dev
#freetype support
sudo apt-get install libfreetype6-dev
#openjpeg200support (needed to compile from source)
wget http://downloads.sourceforge.net/project/openjpeg.mirror/2.0.1/openjpeg-2.0.1.tar.gz
tar xzvf openjpeg-2.0.1.tar.gz
cd openjpeg-2.0.1/
sudo apt-get install cmake
cmake .
sudo make install
#install pillow
pip install pillow
2 of 7
28

Something similar happened to me, I solved this way

sudo apt-get install libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

And try there installing via pip install PIL.

More on what pip is can be found here. In short is a convenient (and becoming a standard) way of installing python libraries.

if it continues to fail, it can be due to PIL searching those libraries in a different path.

It turns out that the APT installations put the libraries under /usr/lib/x86_64-linux-gnu and PIL will search for them in /usr/lib/. So you have to create symlinks for PIL to see them.

Try to see if libjpeg and libz libs exist in /usr/lib/x86_64-linux-gnu and make a symlink this way

sudo ln -s /lib/x86_64-linux-gnu/libz.so.1 /lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so.6 /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so.62 /usr/lib/

Source: http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/

🌐
GitHub
gist.github.com › 2967728
Installing PIL in virtualenvs · GitHub
Thanks to http://devdetails.com/2011/09/20/install-pil-in-a-virtualenv-on-mac-osx-lion/ , here's command line copy/paste to install: brew install jpeg workon myenv pip install --upgrade --no-install PIL sed -i -e 's:JPEG_ROOT = None:JPEG_ROOT ...
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-pil-on-macos
How to Install PIL on MacOS? - GeeksforGeeks
July 23, 2025 - Step 3: Now simply run the following command to install pip(pillow) onto your MacOs:
Top answer
1 of 1
2

you might try to create a virtual environment and install pillow there.

python -m venv ~/myvenv
source ~/myvenv/bin/activate
pip install -U pip
pip install pillow

then use ~/myvenv/bin/python to run the script requiring pillow.

Does this work or do you get the same kind of error message (error: externally-managed-environment )

I'm no expert concerning the "externally-managed-environment" in fact I read it the first time in your post. But a small search seems to indicate that this is a recent enhancement that tries to avoid conflicts between packages installed with apt and packages installed with pip.

So my suggestion to use a venv doesn't seem that bad.

I read https://itsfoss.com/externally-managed-environment/ and it says amongst many other things:

Ubuntu 23.04, Fedora 38 and probably other recent distribution versions are implementing this enhancement on the use of Python packages.

The change has been done to avoid the "conflict between OS package managers and Python-specific package management tools like pip. These conflicts include both Python-level API incompatibilities and conflicts over file ownership."

What are your options?

You can do three things when you try to install a Python package and see this error.

Install the native package
Create virtual environments in Python
Use Pipx (recommended)

I never tried the option pipx (but I it seems it will also create a virtualenv, + some more automatic stuff) However I think pipx works only for executables and not for libraries, so I'd stick with a vinv or a virtualenv at least utnil pipx is better understood

🌐
Readthedocs
pillow-wiredfool.readthedocs.io › en › stable › installation.html
Installation — Pillow v2.7.0 (PIL fork)
We provide binaries for OS X in the form of Python Wheels. Alternatively you can compile Pillow with with XCode. The easiest way to install external libraries is via Homebrew. After you install Homebrew, run: ... Experimental. Requires setuptools >=0.8 and pip >=1.4.1
🌐
GitHub
github.com › python-pillow › Pillow › discussions › 7532
Exception: You don't have PIL installed. Please install PIL or Pillow>=8.1.1 · python-pillow/Pillow · Discussion #7532
Please reload this page. ... I uninstalled and reinstalled it, and moved it into my PATH folder. I used Python -m pip install pillow for my installation, then moved the folder to my PATH folder.
Author   python-pillow
🌐
PyPI
pypi.org › project › pillow › 2.2.2
pip install pillow==2.2.2
We do not provide binaries for OS X. So you’ll need XCode to install Pillow. (XCode 4.2 on 10.6 will work with the Official Python binary distribution. Otherwise, use whatever XCode you used to compile Python.) The easiest way to install the prerequisites is via Homebrew. After you install Homebrew, run: ... Pip does not support Python Eggs; use easy_install instead.
      » pip install pillow
    
Published   Dec 16, 2013
Version   2.2.2
🌐
Edureka Community
edureka.co › home › community › categories › python › installing pil with pip
Installing PIL with pip | Edureka Community
September 11, 2020 - I am trying to install PIL (the Python Imaging Library) using the command: sudo pip install pil ... error: command 'clang' failed with exit status 1