11

I know there are a number of questions already on stackoverflow related to this issue and I have read them all, but still I am having no success with this issue. I am hoping somebody can help me out with this.

I have installed and reinstalled Pillow 10 times now. I have updated my .bash_profile. Still, I get the same error message.

This is my .bash_profile:

export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH="$PATH:/usr/local/bin/"
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

This is my code:

import sys
import string
import re
from PIL import Image

It chokes on the 4th line every time with the message: ImportError: No module named PIL. I have also tried replacing the fourth line with

import Image

also with no success. I know there are many questions similar to this one on here but believe me I have been reading the answers on those with no success so I'm hoping somebody here can help me with my particular situation. Thanks!

swanb034
  • 135
  • 1
  • 1
  • 7
  • 1
    Do you know, for sure, that you have PIL installed? Is it installed at a standard location? If not, did you add the location to your PYTHONPATH? (For imports, python does not use PATH, it uses PYTHONPATH.) – John1024 Oct 28 '14 at 02:14
  • Did you install Pillow using pip? If so, what does `pip freeze | grep Pillow` print? – PM 2Ring Oct 28 '14 at 03:08
  • PM 2Ring, I get the following output: pip freeze | grep Pillow – swanb034 Oct 28 '14 at 03:13
  • oops, forgot to copy, this is what I got: Pillow==2.6.1 – swanb034 Oct 28 '14 at 03:20
  • In response to John1024, I know for sure I have Pillow installed. I installed using pip without specifying a directory so I would assume it is in the same location as all other modules. Does your answer mean I should change instances of PATH in my bash_profile to PYTHONPATH? thanks. – swanb034 Oct 28 '14 at 03:29
  • Ok. pip says pillow is installed, but just to double-check that it's in the right place, look in the '/usr/local/lib/python2.7/dist-packages/' directory. There should be 'PIL/' and 'Pillow-2.6.1.egg-info/' directories. Also, run `python -c ""import sys;print sys.path"` in the shell and make sure the Python path contains '/usr/local/lib/python2.7/dist-packages/'. – PM 2Ring Oct 30 '14 at 02:12
  • Try installing python from `brew`(_if you are on `OSX`. I had a similar kind of error until i used `Pillow` inside my code_). And check if python and pip are running from `brew`'s version. After installing brew, i was able to use pip install without `sudo` – arvindh Aug 13 '15 at 08:21
  • check if [this](http://stackoverflow.com/a/31982615/3869739) helps, – arvindh Aug 13 '15 at 08:28
  • Did you try this ```pip install image```? – Levent Yumerov Aug 30 '16 at 11:43

2 Answers2

13

I was experiencing a similar issue. Fixed it by pip installing WITHOUT sudo.

pip install pillow

instead of

sudo pip install pillow
blearn
  • 1,198
  • 10
  • 17
  • 1
    @YumYumYum Write `py -m pip install pillow` on Windows – cdn Oct 10 '16 at 13:25
  • For me the opposite worked. I had to run a script with `sudo` (so I had to install WITH sudo instead of without it). I asume it has to do with which 'home' directory is used to find modules. If run ***with*** sudo it is installed for the `/root` home directory. If sudo is not used, it uses the current user's home directory (`/home/my-usr`). Thus causing the 'module not found', because sudo commands looks into the /root directory while non-sudo look into the current user's directory. Or so I believe. – Lennin Apr 15 '22 at 00:04
2

I encountered this while installing tensorflow code on NVIDIA Jetson Nano. This works for me:

    pip3 install Image