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.
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
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.
ModuleNotFoundError: No module named 'PIL'
python - how to install PIL with pip? - Stack Overflow
python 3 - How am I supposed to install Pillow (not PIL) on Raspberry Pi OS? - Raspberry Pi Stack Exchange
python - Cannot Install PIL using Pycharm - Stack Overflow
Videos
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
- Install Xcode and Xcode Command Line Tools as mentioned.
- Use Pillow instead, as PIL is basically dead. Pillow is a maintained fork of PIL.
https://pypi.org/project/Pillow/
pip install Pillow
If you have both Pythons installed and want to install this for Python3:
python3 -m pip install Pillow
This works for me:
apt-get install python-dev
apt-get install libjpeg-dev
apt-get install libjpeg8-dev
apt-get install libpng3
apt-get install libfreetype6-dev
ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib
ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib
ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib
pip install PIL --allow-unverified PIL --allow-all-external
In shell, run:
pip install Pillow
Attention: PIL is deprecated, and pillow is the successor.
On some installs of PIL, you must do
import Image
instead of import PIL (PIL is in fact not always imported this way). Since import Image works for you, this means that you have in fact installed PIL.
Having a different name for the library and the Python module is unusual, but this is what was chosen for (some versions of) PIL.
You can get more information about how to use this module from the official tutorial.
PS: In fact, on some installs, import PIL does work, which adds to the confusion. This is confirmed by an example from the documentation, as @JanneKarila found out, and also by some more recent versions of the MacPorts PIL package (1.1.7).
» pip install pillow