Home > Software design >  ModuleNotFoundError: No module named 'PIL' after installing Pillow
ModuleNotFoundError: No module named 'PIL' after installing Pillow

Time:04-20

About a week ago, I had this code running on a different machine but currently I am getting a 'ModuleNotFoundError: No module named 'PIL'' error even though I installed pillow using the command pip install Pillow in the correct directory.

I know this question has been asked a few times but the solutions from them have not worked for me, I have tried a few things...

I am importing pillow using the line

from PIL import ImageTk, Image 

Just trying import Image does not work.

I tried uninstalling pillow where I get the command

Found existing installation: Pillow 9.1.0
Uninstalling Pillow-9.1.0:
  Would remove:
    c:\python39\lib\site-packages\pil\*
    c:\python39\lib\site-packages\pillow-9.1.0.dist-info\*
Proceed (Y/n)?

EDIT:: When running python --version and pip --version I get this.

PS C:\Users\Justin\Desktop\pi\pi-3b > python --version
Python 3.9.4
PS C:\Users\Justin\Desktop\pi\pi-3b > pip --version
pip 22.0.4 from C:\Users\Justin\AppData\Roaming\Python\Python39\site-packages\pip (python 3.9)

EDIT2:: Also, when running pip install Pillow, this is the result

PS C:\Users\Justin\desktop\pi\pi-3b > pip install Pillow
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
Collecting Pillow
  Using cached Pillow-9.1.0-cp39-cp39-win_amd64.whl (3.3 MB)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
Installing collected packages: Pillow
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
Successfully installed Pillow-9.1.0
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
PS C:\Users\Justin\desktop\pi\pi-3b >

CodePudding user response:

Try:

import sys
print(sys.executable)

to see if the Python you are using is the same one pip installed Pillow into.

CodePudding user response:

This is a common issue as PIL deprecates. Your question has been asked before and you can find numerous answers here:

ImportError: No module named PIL

  • Related