I am following the documentation: https://pillow.readthedocs.io/en/stable/
I successfully installed Pillow with pip. However, when I try to import the Image
function I can:
a) Only import it from PIL
b) Only get an error that there is no module PIL
c) Get an error that there is no module Pillow
Here's the message (the same thing happens when I try it with Pillow instead of PIL):
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
And here's proof that I have installed it with pip:
Requirement already satisfied: Pillow in c:\python310\lib\site-packages (8.4.0)
I read on Stackoverflow that PIL is no longer maintained. However, no question answered my problem: ImportError: No module named PIL
CodePudding user response:
You have probably installed Pillow in a different Python installation from the one you are using. pip
and python
are linked to each other. Let's establish what commands you are using first.
Q1 - What command do you use to run Python scripts?
What command do you use when you start Python scripts? Or, if you use a graphical IDE, e.g. VS Code, JetBeans, IDLE, what command does it use to start Python?
Likely answers:
- python
- python-2.7
- python3
So, if the answer is python3
, then in the remainder of the answer YOURPYTHON
will be python3
.
Q2 - What command do you use to install Python packages?
What command do you use to install Python packages?
Likely answers:
- pip
- pip-2.7
- pip3
So, if the answer is pip3
, then in the remainder of the answer YOURPIP
will be pip3
.
You have installed with pip
into your Python 310 installation, you can see that in your "Requirements satisfied" message, or by running:
YOURPIP -V # quick version check
YOURPIP show pillow # more detail as to location
Now the question is which Python are you using? And where is it looking?
YOURPYTHON -V # quick version check
YOURPYTHON -c "import sys; print('\n'.join(sys.path))"
In general, if you use python
, you should probably use pip
. But if you use python3
, you should probably use pip3
to ensure that you are installing into the same place that your interpreter is looking.
You can get information about what is actually running when you type a command like this:
which python # works on macOS, Linux and Windows
type python # works on macOS and Linux and is preferable
CodePudding user response:
Run pip install image --user
and then it should work.
CodePudding user response:
import PIL
from PIL import Image
or
import PIL
from PIL import *
This should solve your problem.