The PIL module is used for image processing. Most of the beginners can get the error ModuleNotFoundError: No module named ‘PIL error while they use the module. In this tutorial, you will learn how to solve this error.
What is the PIL module?
The PIL module comes with the Pillow packages. It allows you to do image processing tasks in Python easily. You can read, write, and change the size of the image using the pillow module. You can also convert the image from one format to other formats like png to jpeg etc.
Reasons for getting the ModuleNotFoundError: No module named ‘PIL’
Let’s find out the reason for getting this error.
Cause 1: Missing Installation
The ‘PIL’ module may not be installed on your system. Python does not come bundled with the ‘PIL’ module by default, so you need to install it separately.
Cause 2: Incorrect Module Name
The module might be named differently on your system. While the official name is ‘PIL’, some systems may use ‘pillow’ as the module name instead.
Cause 3: Module Version Mismatch
If you have multiple versions of the ‘PIL’ module installed on your system, it could lead to conflicts and result in the “ModuleNotFoundError: No module named ‘PIL'” error.
Steps to solve No module named ‘PIL’ Error
Now you have known the reasons for the error below are the steps to follow to solve the error.
Step 1: Check if the ‘PIL’ Module is Installed
First, you need to check whether the ‘PIL’ module is installed on your system. Open your command prompt or terminal and enter the following command:
pip show pillow
If the module is installed, you will see the details of the installed version. If it is not installed, you will get an error message indicating that the package is not found.
Step 2: Install the ‘PIL’ Module
If the ‘PIL’ module is not installed, you need to install it. Use the following command to install the ‘PIL’ module. The pip command will depend upon the Python version in your system.
pip install pillow # For python 2.xx pip3 install pillow # For python 3.xx
This command will download and install the latest version of the ‘PIL’ module on your system.
Step 3: Check the Module Name
If the ‘PIL’ module is installed, but you are still getting the error, it might be due to a different module name. In such cases, try importing the ‘PIL’ module using the alternate name ‘pillow’. Update your import statement to:
from PIL import Image
from pillow import Image
Step 4: Verify Module Version
If you have multiple versions of the ‘PIL’ module installed, it can lead to conflicts. To verify the installed versions, use the following command:
pip freeze | grep pillow
This command will display all the installed versions of the ‘pillow’ module. If you find multiple versions, uninstall the older versions using the following command:
pip uninstall pillow==
Replace ” with the specific version you want to uninstall.
Step 5: Restart Your IDE
After following the above steps, restart your integrated development environment (IDE) or editor to ensure that the changes take effect.
By following these steps, you should be able to resolve the “ModuleNotFoundError: No module named ‘PIL'” error. Remember to install the ‘PIL’ or ‘pillow’ module, check the module name, verify the module version, and restart your IDE.
In most cases, the ModuleNotFoundError occurs when the Python interpreter is unable to find the module installed in the system. The error ModuleNotFoundError: No module named ‘PIL’ is the same. You have to install the module to avoid this error. The above are the steps you should follow to avoid the error.