Modulenotfounderror: no module named pil error occurs if the pillow package is not installed or not properly configured. The best way to resolve this error is to reinstall the pillow module again. In some of the cases, the same error occurs because of importing the PIL module in the place of the image module. In this article, we will see the different easiest ways to install pillow modules. Also, we will address the import issue. So let’s start.
What is the Pillow (pil ) Python module?
The pillow module allows you to manipulate and save images in different file formats like JPEG, PNG, BMP, GIF, TIFF, and others. You can perform many operations like cropping, resizing, rotating, color conversions, and more. You can also do image processing operations like filtering and enhancing. In addition, it allows you to add watermarks or captions to the images.
Modulenotfounderror: no module named pil ( Solution )-
The best and easiest way to install any python package is using any package manager either pip, conda, or some other like easy_install. Here in a single line command we can install any python package.
Solution 1: pip for pillow installation –
Use this command to install the pillow with the pip package manager.
pip install Pillow
We can install any version of the pillow by just adding the version in the pillow command. For version, detail refers to the release details of pillow.
pip install Pillow==9.2.0
For admin rights please add sudo keyword in Linux similar OS and In windows, launch the cmd in Admin mode. If you are getting permission issues.
If pip is not properly configured then run the below command.
python -m pip install Pillow
Solution 2: conda for pillow installation –
conda comes with Anaconda distribution.
conda install -c conda-forge pillow
Here we can change the mirrors just like in the above command we are using conda-forge mirror we can use the below mirror as well.
Solution 3: Source for pillow installation –
Here we will build pillow packages locally. For this, we need to download the source code for the pillow package and then run the
python install setup.py
We need to take care of few import statements like –
1. In the place of
from PIL import Image
2. In the place of
from PIL.Image import core as _imaging
Other Must Read –
opencv is more over related libraries like pil. Hence you want to explore more the installation and operations of opencv, please read the below article.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.