No Module named PIL

In my case the problem had to do with virtual environments.

The python program ran in a virtual environment, but I called pip install Pillow from a normal command prompt. When I ran the program in a non-virtual environment, from PIL import Image worked.

It also worked when I called venv/scripts/activate before calling pip install Pillow. So apparently PIL is not found when installed in the python root but the program runs in a virtual environment.


Alright, I found a fix

To fix the issue, I uninstalled PIL and Pillow through sudo pip3 uninstall pillow and sudo apt-get purge python3-pil. I then restarted and then used sudo -H pip3 install pillow to reinstall Pillow

The only step I was missing before was rebooting, and not reinstalling PIL afterwards.

It seems to have worked without any issues so far.


Had the same problem before and I tried:

 pip install pillow 
 pip install image 

import PIL --> still did not work

then I found out that it was installed as pil

c:\python36\lib\site-packages\pil

import pil

pil.__version__

'5.1.0'

I am using ubuntu 18.04 and I was facing exactly same issue after installing pillow following the official documentation. I tried all hacks shared by other users but no solution. But the problem got immediately resolved when I installed python-pil using the following command:

sudo apt-get install python3-pil