369

I use this command in the shell to install PIL:

easy_install PIL

then I run python and type this: import PIL. But I get this error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

I've never had such problem, what do you think?

5
  • 16
    @RikPoggi This page of documentation actually tells to use from PIL import Image, which does not work. May 4, 2012 at 7:30
  • 2
    @Janne just use Import Image,and PIL starts working. May 11, 2012 at 9:40
  • 2
    At this time I'd recommend to easy_install Pillow instead. Pillow is a fork of PIL that has better packaging and supports Python 3. Jul 23, 2013 at 10:48
  • 1
    Can you change the accepted answer to one that recommends Pillow? As @LennartRegebro said, this package is better long-term. Aug 28, 2019 at 20:44
  • 2
    Use pip install Pillow instead. Then you can do import PIL.Image Jan 27, 2021 at 8:54

31 Answers 31

510

In shell, run:

pip install Pillow

Attention: PIL is deprecated, and pillow is the successor.

6
  • 8
    Really? image is not the PIL module of the question, it's instead a "Django application" (that happens to be based on PIL). Reference: github.com/francescortiz/image. Jan 21, 2017 at 18:30
  • 7
    pip install image worked for me. thanks to duckduckgo cache for holding onto pre-edit answer!
    – Zahra
    Sep 15, 2018 at 22:01
  • I've seen PILLOW other places, Pillow here. cmd is not case-sensitive, but what is the preferred way of writing this? Aug 28, 2019 at 20:43
  • installing image with that weird django thing got this script i found to run at least. It didn't get far enough to test the package though.
    – Pysis
    Sep 19, 2019 at 0:59
  • 2
    When I key "pip install Pillow" in Terminal, it appears this error: Requirement already satisfied: Pillow in c:\users\user\venv\odoo\lib\site-packages (6.2.2)
    – Akira Chen
    May 22, 2020 at 14:44
184

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).

12
  • 221
    pip install image from Zhiming's answer worked for me. Oct 14, 2015 at 22:42
  • 10
    yup, @JimSchubert said it. pip install image from @zhimmingwang worked for me too Nov 4, 2015 at 14:04
  • 8
    But image is not PIL (as in the question), it's a different module. Reference: github.com/francescortiz/image. Am I missing something, here? Jan 21, 2017 at 18:31
  • 2
    I got the same error "ImportError: No module named PIL". Installed Pillow with "pip install Pillow" and tried to run the script. Still got the same error. Then, I tried to import an image, it says 'No module named image' found. I installed image using 'pip install image' and tried again. No luck. Any suggestions?
    – user3252885
    Oct 11, 2017 at 15:47
  • 3
    You should check that your pip installs for the python interpreter that you are using. pip -V tells you where it installs. Under Unix, which python tells you where your python command is. The two should match well enough. Or, better: python -c 'import sys; print sys.path' will tell you where your python command looks for modules (print(sys.path), for Python 3). Oct 26, 2017 at 8:34
72

At first install Pillow with

pip install Pillow

or as follows

c:\Python35>python -m pip install Pillow

Then in python code you may call

from PIL import Image

"Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used." From pillow installed, but "no module named pillow" - python2.7 - Windows 7 - python -m install pillow

1
  • 14
    i am getting Requirement already satisfied but still the same issue Jun 3, 2016 at 4:49
72

On a different note, I can highly recommend the use of Pillow which is backwards compatible with PIL and is better maintained/will work on newer systems.

When that is installed you can do

import PIL 

or

from PIL import Image

etc..

2
27

Sometimes I get this type of error running a Unitest in python. The solution is to uninstall and install the same package on your virtual environment.

Using this commands:

pip uninstall PIL

and

pip install  PIL 

If for any reason you get an error, add sudo at the beginning of the command and after hitting enter type your password.

5
  • 2
    This also works for me. Consider that one might use other Python scripts that indirectly uses PIL, changing the Import statement is not always an option. Jul 25, 2013 at 22:28
  • 1
    This didn't work for me, it couldn't find a repository called PIL (or pil). However I ran "pip install Pillow" which did work. My understanding is that Pillow is a branch of PIL. Oct 30, 2014 at 16:54
  • @TeeBasins Pillow is the “friendly PIL fork” by Alex Clark and Contributors.
    – user4396006
    Jul 6, 2015 at 9:47
  • 2
    I get " Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL"
    – J.Doe
    May 21, 2018 at 1:07
  • This worked for me but after I updated the pip installer.... To update, run: python.exe -m pip install --upgrade pip ---> pip uninstall Pillow ----> pip install Pillow
    – M.KD
    Sep 13, 2023 at 7:41
26

This worked for me on Ubuntu 16.04:

sudo apt-get install python-imaging

I found this on Wikibooks after searching for about half an hour.

4
  • 3
    This question was asked before the Ubuntu 16.04, but I met this problem in Ubunt 16.04 and fixed it with your suggestion.
    – foool
    Jan 13, 2017 at 3:21
  • Glad I could help! :D
    – grooveplex
    Jan 13, 2017 at 11:00
  • This was my issue on a RPI with an OLED screen displaying python output
    – Ryan Ellis
    Mar 4, 2019 at 0:37
  • This fixed my issue with Pillow but my actual problem was that python 2 was used when I typed python in the command line instead of python3 (you can check for this with python -V)
    – fourk
    Dec 9, 2021 at 21:26
17

you have to install Image and pillow with your python package.

type

python -m pip install image 

or run command prompt (in windows), then navigate to the scripts folder

cd C:\Python27\Scripts

then run below command

pip install image
2
  • For python3 use python3 -m pip install Pillow
    – Judder
    Jun 23, 2021 at 15:59
  • Uninstalling Pillow and then installing image worked for me. Oct 27, 2021 at 18:03
15

I used:

pip install Pillow 

and pip installed PIL in Lib\site-packages. When I moved PIL to Lib everything worked fine. I'm on Windows 10.

15

On windows 10 I managed to get there with:

cd "C:\Users\<your username>\AppData\Local\Programs\Python\Python37-32" 
python -m pip install --upgrade pip     <-- upgrading from 10.something to 19.2.2.
pip3 uninstall pillow
pip3 uninstall PIL
pip3 install image

after which in python (python 3.7 in my case) this works fine...

import PIL
from PIL import image
1
  • After upgrading windows 7 to windows 10 my python program didn't work but this method solved it. Thanks!
    – user1785594
    Dec 16, 2019 at 10:20
13

Install Specific Version:

pip install Pillow

Upgrade Pillow

sudo pip3 install --upgrade Pillow

Getting Dependency Error in Window 10 Use code: easy_install instead of pip install

easy_install Pillow 

Upgrade using easy install

sudo easy_install --upgrade  Pillow

On OSX System to install Module: Use code: brew install instead of pip install

brew install Pillow 

Without Using Pip :

 sudo apt-get install -y Pillow 

On CentOS7 or Linux Fedora:

yum -y install Pillow 

Or on Fedora try

sudo dnf install Pillow 

Command if Homebrew screws up your path on macOS:

python -m pip install Pillow 

For Python3 MacOs Homebrew screws

python3 -m pip install Pillow

Verify module from list MacOs

pip freeze | grep  Pillow

For Execute on Anaconda as your python package manager

 conda install -c anaconda Pillow 
1
  • upgrading the Pillow did it for me on windows11
    – Fathy
    Aug 27, 2022 at 16:25
9

On windows, try checking the path to the location of the PIL library. On my system, I noticed the path was

\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL  

after renaming the pil folder to PIL, I was able to load the PIL module.

1
  • I was also getting same import error. I have installed PIL using easy_install. In site-packages it was installed in directory with 'PIL-1.1.7-py2.7-win32.egg' name. As per your suggestion i have changed the dir name to PIL and it worked. Thanks for your help @Komla. Feb 25, 2014 at 5:42
8

if you use anaconda:

conda install pillow
2
  • 1
    I did this, it still couldnt import PIL
    – john k
    Aug 22, 2019 at 5:19
  • @johnktejik which version of Python and Anaconda are you using?
    – Conor
    Aug 25, 2019 at 18:38
8

The cleanest way to resolve this issue is by following below steps.

Step 1: Uninstall the PIL package.

pip uninstall PIL

Step 2: Install the Pillow using pip as shown below on windows operating systems. For other environments checkout the article No module named PIL

On Windows

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

Step 3: The most crucial class in the Python Imaging Library is the Image class, and you can import this as shown below.

from PIL import Image
im = Image.open("myimage.jpg")

If successful, this function returns an Image object. You can now use instance attributes to examine the file contents:

print(im.format, im.size, im.mode)

#Output: PPM (512, 512) RGB
2
  • This has worked for me on windows 11. Feb 9, 2023 at 11:28
  • This worked for me on macOS Monterey, after every other face_recognition/dlib install python fix failed. I needed to downgrade to py 3.9 from 3.11 tho.
    – volvox
    Mar 12, 2023 at 23:05
7

I had the same issue on windows 10 and this worked for me:

pip install Pillow

6

You will need to install Image and pillow with your python package. Rest assured, the command line will take care of everything for you.

Hit

python -m pip install image

6

instead of PIL use Pillow it works

easy_install Pillow

or

pip install Pillow
5
pip(3) uninstall Pillow
pip(3) uninstall PIL
pip(3) install Pillow
5

This worked for me on Ubuntu 20.04:

pip install image

And in script:

import image
2

use pil instead of PIL

from pil import Image
2

I found an easier solution. Use a virtual environment.

pip install Pillow
from PIL import Image

This works for me on a macOS

1

On Windows, you need to download it and install the .exe

https://pypi.python.org/pypi/Pillow/2.7.0

1

I used conda-forge to install pillow version 5, and that seemed to work for me:

conda install --channel conda-forge pillow=5

the normal conda install pillow did NOT work for me.

1

I had the same problem and i fixed it by checking what version pip (pip3 --version) is, then realizing I'm typing python<uncorrect version> filename.py instead of python<correct version> filename.py

1

I used :

from pil import Image

instead of

from PIL import Image

and it worked for me fine

wish you bests

0

I had the same issue while importing PIL and further importing the ImageTk and Image modules. I also tried installing PIL directly through pip. but not success could be achieved. As in between it has been suggested that PIL has been deprectaed, thus, tried to install pillow through pip only. pillow was successfully installed, further, the PIL package was made under the path : python27/Lib/site-packages/.

Now both Image and ImageTk could be imported.

0

I recently installed Leap. I Tried openshot and it didn't start. So came here and found a suggestion to start from the Terminal to see if there were any error.

The error I had was error missing mlt. So I installed the python-mlt module from Yast and imported it, tried to start but next openshot said missing pil.

I Followed the Pillow suggestion to install because Yast couldn't find any pil and imported pil. That went ok but did not start and showed Error missing goocanvas.

The I installed goocanvas with Yast, imported it in python, and Openshot fired up !!

With a lot of errors in the terminal like missing Vimeoclient and lots of attributeerrors. Well, will see if it is of any influence working with it.

0

Python 3.8 on Windows 10. A combination of the answers worked for me. See below for a standalone working example. The commented out lines should be executed in the command line.

import requests
import matplotlib.pyplot as plt
# pip uninstall pillow
# pip uninstall PIL
# pip install image
from PIL import Image
url = "https://images.homedepot-static.com/productImages/007164ea-d47e-4f66-8d8c-fd9f621984a2/svn/architectural-mailboxes-house-letters-numbers-3585b-5-64_1000.jpg"
response = requests.get(url, stream=True)
img = Image.open(response.raw)
plt.imshow(img)
plt.show()
0

I had the same issue and tried many of the solutions listed above.

I then remembered that I have multiple versions of Python installed AND I use the PyCharm IDE (which is where I was getting this error message), so the solution in my case was:

In PyCharm:

go to File>Settings>Project>Python Interpreter

click "+" (install)

locate Pillow from the list and install it

Hope this helps anyone who may be in a similar situation!

0

According to the official websiteInstall Pillow, you may want to try this:

go to Terminal and run:

  • python3 -m pip install --upgrade pip

Then Run on

  • source ~/.bash_profile
0

I installed Pillow through my terminal which used Python 3.11. My IDE (PyCharm) was set to Python 3.12 as an interpreter. I changed that and it worked.

Not the answer you're looking for? Browse other questions tagged or ask your own question.