Pillow: No module named PIL

Created on 14 May 2019  Â·  22Comments  Â·  Source: python-pillow/Pillow

What did you do?

i did pip install pillow and wrote from PIL import Image
but when i run it it just say no module named PIL

What did you expect to happen?

it would run fine and give no errors

What actually happened?

I got the error "no module named PIL"

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.6
  • Pillow: 6.0.0
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw 

img = Image.new('RGB', (800,1280), (255, 255, 255))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("sans-serif.ttf", 16)
draw.text((0, 0),"Sample Text",(255,255,255),font=font)
Installation

Most helpful comment

change PIL with pil
It works for me

All 22 comments

Could you actually show us the output of pip install Pillow and import PIL?

I don't suppose that you have two versions of Python set up, and you are installing into one and then trying to import from the other?

it is installing for the right version,
i didnt have import PIL but i just tried and same error,

edit:
C:\Users\cs-admin\PycharmProjects\DiscordBot\venv>pip install pillow
Collecting pillow
Using cached https://files.pythonhosted.org/packages/e6/37/fc5bde88462cf8a069e522dd6a0d259b69faba1326f0a3ce8b4e11d9f317/Pillow-6.0.0-cp36-cp36m-win_amd64.whl
Installing collected packages: pillow
Successfully installed pillow-6.0.0

Since you have 'venv' in your path, I presume that the answer to this question involves the fact that you're using a virtual environment. https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/ might prove useful.

Otherwise, a quick solution might be -

  • If you run pip show Pillow, the location of the Pillow package will be shown.
  • If you run python -m site, one of paths shown will be the location of your Python install's site-packages directory.
  • If you copy Pillow from the pip location to the Python site-packages directory, you should be able to import Pillow after that.

Here's the thing:
Pip location : c:\users\cs-adminappdata\local\programs\python\python36\lib\site-packages

Install location : 'C:\Users\cs-admin\AppData\Local\Programs\Python\Python36\lib\site-packages',

change PIL with pil
It works for me

change PIL with pil
It works for me

simple solution, but it was really pain.... Thanks

sorry to comment on this old question but I already tried this and this was working but now when I do "import PIL" it says "no module named PIL" but when I do "import pil" it gave the same error "no module named PIL" in capital letters.

change PIL with pil
It works for me

it doesnt for me.
literally all i want to do is show an image in python.
i have been trying for hours.
someone please help me.

Edit: incase this matters, i went to the file location of where pip said it installed pillow, but couldnt find anything to do with pillow.

Edit 2: actually i found it, it was installed in C: instead of C:\Users\\AppData\Local\Programs\Python
thats definitely a bad thing, right? if anyone could please help me i would be so grateful.

Edit 3: ok, now ive fixed it, but its saying "cannot import name '_imaging' from 'PIL'
that's weird, as i told it to import "Image", not "_imaging". does anyone have a solution?

I found a solution that worked for me :
First I uninstalled the old version of pil located for me in %localappdata%\Programs\Python\Python37-32\Lib\site-packages\ and removed the pil folder
Then I updated Pillow using pip install Pillow==7.1.2 and adding the version was necessary because otherwise, it will install the latest version of Pillow that can work for every dependency
And then doing from PIL import Image worked

change PIL with pil
It works for me

thanks

When I exited my virtual environment it seemed to work

i hope this helps but i belive your python is 3 version which means for you to execute the script you made instead of typing "python script.py" , you should instead use "python3 script.py" and that because you must have 2 versions of python and the pillow path in the python 3 part while the execution was made on python2 i hope this help because that what worked for me

oh em gi
i have the same problem and nothing seems to work :(
Screenshot_7

For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py

For me it was a python version problem. Fixed it by using pip3 install Pillow and then starting the script with python3 script.py

Yep, that's why the installation instructions recommend python3 -m pip install --upgrade pillow

And it's recommended to do that generally: https://snarky.ca/why-you-should-use-python-m-pip/

Exactly, I tried everything on the internet, nothing seems to work

Thankfully, it's now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/

This time, I installed it in (I changed the location with the help of that website):
C:\Users\\AppData\Local\Programs\Python\Python38-32\Scripts

Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn't already.

Then import PIL in Python and it'll work!

Thankfully, it's now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/

This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts

Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn't already.

Then import PIL in Python and it'll work!

Could you please write down your approach step by step?

I'd like to try this suggestion but I am not sure if I can follow the directions correctly now.

Thankfully, it's now working. What I did was, I deleted pip from the location where it was saved, which in my case was:
C:\Users\AppData\Local\Microsoft\WindowsApps. Then I installed it again using this website: https://datatofish.com/upgrade-pip/
This time, I installed it in (I changed the location with the help of that website):
C:\Users\AppData\Local\Programs\Python\Python38-32\Scripts
Then I used pip install pillow and installed it in the same place, Python Scripts area given above. Uninstall it using pip uninstall pillow if it wasn't already.
Then import PIL in Python and it'll work!

Could you please write down your approach step by step?

I'd like to try this suggestion but I am not sure if I can follow the directions correctly now.

Sure.

When I installed pillow from command prompt, I just entered the command pip install pillow and not specified any location, so it installed pillow to the default location, which in my case was C:\Users\<User Name>\AppData\Local\Microsoft\WindowsApps (I'm pretty sure it's the same in yours too).

So I went there (C:\Users\<User Name>\AppData\Local\Microsoft\WindowsApps) and manually deleted pip from there the usual way like we delete files. Then, I installed pip using this website: https://datatofish.com/upgrade-pip/ to this location: C:\Users\<User name>\AppData\Local\Programs\Python\Python38-32\Scripts.

After I installed pip, using the same cd\ and cd (Given in the site), I changed the location to C:\Users\<User name>\AppData\Local\Programs\Python\Python38-32\Scripts and wrote pip install pillow. In the previous answer, I've written use pip uninstall pillow if it is already installed, but I guess it'll uninstall itself if the whole pip is deleted. Still, to be on the safer side, you can use pip uninstall pillow first before installing.

Try importing PIL again in Python, and it should work!

Hope it helps ☺

the thing is , if you install 'P'illow the debugger will be expecting PIL and if you're installing 'p'illow it will be expecting pil , apparently each one of them is somehow separated

now this is worst for linux users

I'm going to lock this issue because brief comments like "now this is worst for linux users" don't really help anyone, let alone us help you.

If you're having problems installing, please open a new issue _with details_, and we'll try and help out:

https://github.com/python-pillow/Pillow/issues/new/choose

Thank you!

Was this page helpful?
0 / 5 - 0 ratings