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
» pip install pillow
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
The problem is that you are not running the same python interpreter. In addition, the problem could arise from this fact that python cannot find the path to the OpenCV.
You first need to find the path to the OpenCV installed on your OS.
First, open a python script and run this:
import cv2
PATH = cv2.__file__
print(PATH)
This will print the PATH to the OpenCV installed on your OS.
Then, add the following two lines to the top of your main script (before calling tkinter and PIL):
import sys
sys.path.append('PATH')
from tkinter import *
from PIL import ImageTk, Image
root.mainloop()
Alternative Solution:
The problem could be that you are not running the same python interpreter.
You first need to find the path to the python executable that is interpreting your python scripts.
Open a python script and run this:
import sys
PATH = sys.executable
print(PATH)
This will print the path to the python executable that is interpreting your python scripts.
Now, you can install pillow in the found path as follows:
PATH -m pip install pillow
Import PIL does not work when Pillow is installed via pip
python 3 - How am I supposed to install Pillow (not PIL) on Raspberry Pi OS? - Raspberry Pi Stack Exchange
Probelms with Pillow: from PIL import image // modulenotfounderror no module named 'PIL'
How do I install Pillow (PIL) in Visual Studio?
Videos
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.
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
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/
I want to edit an image using PIL but I can't figure out how to install it on Windows? Can someone please help? I have no idea what I'm doing
Pillow is a maintained fork of PIL, so I recommend using Pillow. But you can't have both installed at the same time.
First, remove both PIL and Pillow.
Then install Pillow with
pip install pillow(although, depending on platform, you may need some prerequisites).Then make sure code is using
from PIL import Imagerather thanimport Image.
You can try using Pillow instead, which is a PIL fork:
pip install Pillow
To import use following:
from PIL import Image
» pip install pillow