ModuleNotFoundError: No module named 'PIL' while importing matplotlib

while importing matplotlib i am getting an error "ModuleNotFoundError: No module named ‘PIL’ " in jupyter notebook on my laptop. i have installed both matplotlib and pillow using pip. i cant plot a graph because of this. what should i do.

!pip install pillow

I did that still same error

Did the package install successfully?

You should do it inside the notebook BTW.

yes i did in notebook before importing matplotlib
and yes it was installed successfully without any errors.
and if i install it again i get Requirement already satisfied

Things I would try:

  1. Check if from PIL import Image works
  2. pip install --upgrade --force-reinstall pillow.
    1. The same for matplotlib
  3. Perhaps you have PIL installed (it’s something a bit different). Uninstall it.
  4. Some info on the net says that you should also pip install image
1 Like

the second step worked.

thank you so much for helping