timdika
timdika

Reputation: 188

Python Pillow (or PIL) not working despite PIP installation

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

Upvotes: 3

Views: 6729

Answers (3)

Lork56800
Lork56800

Reputation: 1

When I used the command py [filename] it didn't work but when I tried python [filename] it worked just fine, so I guess you better use the python command than the abbreviated one py.

Upvotes: 0

Mark Setchell
Mark Setchell

Reputation: 207660

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
YOURPIP debug             # lots of detail about how pip is set up

Now the question is which Python are you using? And where is it looking?

YOURPYTHON -V                                            # quick version check
YOURPYTHON -c "import sys; print(sys.executable)"        # where is my Python interpreter?
YOURPYTHON -c "import sys; print('\n'.join(sys.path))"   # where does it look for packages?

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

Upvotes: 6

FourBars
FourBars

Reputation: 565

Run pip install image --user and then it should work.

Upvotes: 1

Related Questions