Skip to content
Home » ImportError: No module named PIL

ImportError: No module named PIL

To solve ImportError: No module named PIL error follow below methods.

ERROR LOG

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

How to solve ImportError: No module named PIL ?

If you use the Python image library and import PIL, you may receive the error ImportError: No module named PIL when starting the project. It occurs as a result of the PIL library’s degradation. Instead, you should install and use its successor pillow library to remedy the problem.

Method 1:

PIL is deprecated, and pillow is the successor.

pip install Pillow

Method 2 :

On Windows

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

On Linux

easy_install Pillow 

On OSX  

brew install Pillow 

Note: You may encounter this problem while importing matplotlib into your Jupyter notebook, and a typical Pillow installation may not work. To address the problem, you could perform a force install of Pillow, as indicated below.

pip install --upgrade --force-reinstall Pillow
pip install --upgrade --force-reinstall matplotlib

Step 3: The most crucial class in the Python Imaging Library is the Image class, and you can import this as shown below.

from PIL import Image
im = Image.open("image.jpg")

Hope the above solution works.

Also read :

TypeError: unhashable type: ‘list’
TypeError: unhashable type: ‘dict’