Are you getting the error “modulenotfounderror: no module named ‘PIL’“? Well, you have come to the right place. In this tutorial, I will show you how to solve this error.
This error occurs “modulenotfounderror: no module named pil” when we forget to install the “pillow” package before importing it into the Python program. We can solve this error by installing the “Pillow” module before importing it into the program.
[Fixed]: ModuleNotFoundError: No module named ‘bs4’
[Fixed] ModuleNotFoundError: No module named ‘PIL’
The best way to solve this problem is the installation Pillow using the below command.
Before installing the Pillow, uninstall PIL first.
pip uninstall PIL
In a virtual environment or using Python 2 use this command
pip install Pillow
For python 3
pip3 install Pillow
If you get a permissions error you can run the command as an admin
sudo pip3 install Pillow
pip install Pillow --user
If you don’t have pip in your PATH environment variable you can use Python -m
python -m pip install --upgrade Pillow
For python 3 you can use this command
python3 -m pip install --upgrade Pillow
Using py alias (Only works on Windows)
py -m pip install --upgrade Pillow
If you are programming with Anaconda
conda install -c conda-forge pillow
If you are using Jupyter Notebook
!pip install Pillow
You must have to uninstall PIL before installing Pillow because these 2 packages can’t exist in the same environment.
When you successfully installed the Pillow package you can import PIL like the code example below:
from PIL import Image
img = Image.open("image.png")
img.show()
Conclusion on ModuleNotFoundError: No module named ‘PIL’
Programmers, We discussed how we can solve the error “modulenotfounderror no module named pil“. I hope you will solve this error with the help of this tutorial. If you tried all commands but still getting this error, please let us know in the comments section.