Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named PIL #3851

Closed
cheekysim opened this issue May 14, 2019 · 22 comments
Closed

No module named PIL #3851

cheekysim opened this issue May 14, 2019 · 22 comments
Labels
Installation Usually a problem with …

Comments

@cheekysim
Copy link

cheekysim commented May 14, 2019

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)
@radarhere
Copy link
Member

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?

@radarhere radarhere added the Installation Usually a problem with … label May 14, 2019
@cheekysim
Copy link
Author

cheekysim commented May 14, 2019

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

@radarhere
Copy link
Member

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.

@cheekysim
Copy link
Author

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

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

@Hassani87
Copy link

change PIL with pil
It works for me

@walhekav
Copy link

change PIL with pil
It works for me

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

@Escartem
Copy link

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.

@Lassie23
Copy link

Lassie23 commented Jun 19, 2020

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<user>\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?

@Escartem
Copy link

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

@alfredomaussa
Copy link

change PIL with pil
It works for me

thanks

@akackon
Copy link

akackon commented Jul 11, 2020

When I exited my virtual environment it seemed to work

@ahmedmaz24
Copy link

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

@danielcovaci
Copy link

danielcovaci commented Sep 4, 2020

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

@vienom
Copy link

vienom commented Sep 16, 2020

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

@hugovk
Copy link
Member

hugovk commented Sep 16, 2020

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/

@PianoPianist
Copy link

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

@PianoPianist
Copy link

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<My folder name>\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<Folder name>\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!

@znym
Copy link

znym commented Nov 6, 2020

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.

@PianoPianist
Copy link

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 ☺

@JawharBA
Copy link

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

@MoreTemi
Copy link

MoreTemi commented Dec 3, 2020

now this is worst for linux users

@hugovk
Copy link
Member

hugovk commented Dec 3, 2020

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!

@python-pillow python-pillow locked as resolved and limited conversation to collaborators Dec 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Installation Usually a problem with …
Projects
None yet
Development

No branches or pull requests