254

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?

Eric O Lebigot
  • 81,422
  • 40
  • 198
  • 249
Asma Gheisari
  • 4,564
  • 7
  • 27
  • 47

25 Answers25

337

In shell, run:

pip install Pillow

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

sehe
  • 328,274
  • 43
  • 416
  • 565
zhiming wang
  • 3,411
  • 2
  • 9
  • 2
  • 7
    Really? `image` is _not_ the PIL module of the question, it's instead a "Django application" (that happens to be _based_ on PIL). Reference: https://github.com/francescortiz/image. – Eric O Lebigot Jan 21 '17 at 18:30
  • 8
    Why does this have upvotes? `image` may be a useful library, but it is unrelated to the question. – gwg Mar 21 '17 at 15:00
  • 3
    `pip install image` worked for me. thanks to duckduckgo cache for holding onto pre-edit answer! – Zahra Sep 15 '18 at 22:01
  • This method is helpful to me. – Bravo Yeung Jun 06 '19 at 03:50
  • I've seen PILLOW other places, Pillow here. `cmd` is not case-sensitive, but what is the preferred way of writing this? – Josiah Yoder Aug 28 '19 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 '19 at 00:59
  • 1
    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 '20 at 14:44
  • DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Pyth on 2.7 is no longer maintained. pip 21.0 will drop sup port for Python 2.7 in January 2021. More details abou t Python 2 support in pip, can be found at https://pip .pypa.io/en/latest/development/release-process/#python -2-support – Akira Chen May 22 '20 at 15:09
160

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

Eric O Lebigot
  • 81,422
  • 40
  • 198
  • 249
  • 188
    `pip install image` from Zhiming's answer worked for me. – Jim Schubert Oct 14 '15 at 22:42
  • 9
    yup, @JimSchubert said it. `pip install image` from `@zhimmingwang` worked for me too – Rafael Ruiz Muñoz Nov 04 '15 at 14:04
  • 7
    But `image` is _not_ PIL (as in the question), it's a different module. Reference: https://github.com/francescortiz/image. Am I missing something, here? – Eric O Lebigot Jan 21 '17 at 18:31
  • 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? –  Oct 11 '17 at 15:47
  • 2
    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). – Eric O Lebigot Oct 26 '17 at 08:34
  • When I installed Pillow with conda, `import PIL` works. Not sure if that's an exception or the rule – emporerblk Aug 22 '18 at 17:58
  • This is the official way of importing Pillow, which is a more modern fork (https://pillow.readthedocs.io/en/latest/handbook/tutorial.html). Note that the `import Image`of this answer thus seems to be `from PIL import Image`, with Pillow. – Eric O Lebigot Sep 10 '18 at 09:19
  • 1
    @EricOLebigot Yours is a seemingly underappreciated solution, your suggestion resolved my issue perfectly, and prevented me from downloading any other packages – Scott Anderson Jan 15 '19 at 23:01
  • 1
    This Should be `import image` (note the lowercase "i") - after all you are running `pip install image` also with a lowercase i – Michael Romrell Apr 16 '20 at 06:39
  • `pip3 install image` in my case, look for your python version. `python -V` – Andres Paladines Nov 11 '20 at 18:17
61

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

kba
  • 957
  • 8
  • 20
Damian
  • 2,396
  • 21
  • 19
55

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

Community
  • 1
  • 1
Orhan Celik
  • 1,314
  • 13
  • 11
21

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.

Anshul Goyal
  • 61,070
  • 31
  • 133
  • 163
Fernando Munoz
  • 3,141
  • 1
  • 15
  • 16
  • 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. – PropellerHead Jul 25 '13 at 22:28
  • 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. – Seb Charrot Oct 30 '14 at 16:54
  • @TeeBasins Pillow is the “friendly PIL fork” by Alex Clark and Contributors. –  Jul 06 '15 at 09: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 '18 at 01:07
21

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.

grooveplex
  • 2,131
  • 4
  • 24
  • 28
13

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.

cromastro
  • 151
  • 1
  • 4
13

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
andrew pate
  • 2,773
  • 26
  • 17
12

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
azdoud
  • 1,094
  • 8
  • 15
8

if you use anaconda:

conda install pillow
Conor Cosnett
  • 745
  • 9
  • 18
7

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.

Robert
  • 5,191
  • 43
  • 59
  • 113
Komla
  • 71
  • 1
  • 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. – shashaDenovo Feb 25 '14 at 05:42
  • this worked for me, thanks a milion – developer Dec 18 '20 at 15:52
5

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

5

instead of PIL use Pillow it works

easy_install Pillow

or

pip install Pillow
Sai Gopi Me
  • 9,800
  • 1
  • 65
  • 43
4
pip(3) uninstall Pillow
pip(3) uninstall PIL
pip(3) install Pillow
Newt
  • 446
  • 3
  • 11
3

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 
2

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.

Geoff Perrin
  • 389
  • 1
  • 4
  • 12
1

I used :

from pil import Image

instead of

from PIL import Image

and it worked for me fine

wish you bests

Heydar
  • 107
  • 8
1

use pil instead of PIL

from pil import Image
Newt
  • 446
  • 3
  • 11
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.

Thomasleveil
  • 69,168
  • 10
  • 106
  • 102
Johan
  • 1
0

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

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()
Jortega
  • 2,423
  • 14
  • 16
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!

-13

You are probably missing the python headers to build pil. If you're using ubuntu or the likes it'll be something like

apt-get install python-dev
Crankyadmin
  • 157
  • 1
  • 7
  • What architecture are you using, if 64bit you're in for a world of hurt. Use a 32 bit version and use the unofficial precompiled version from [here](http://mail.python.org/pipermail/image-sig/2009-September/005872.html) – Crankyadmin Jan 14 '12 at 17:47
  • It's 32 bit,I've installed this for several times,but this this time I have this problem – Asma Gheisari Jan 14 '12 at 17:53