Fix: import error no module named image

In Python, the “image” module is used to load the image for processing. This module belongs to the “Pillow” library that supports a variety of built-in functionalities such as creating, loading, and editing images. While using the “image” module in Python, the error “import error no module named image” might occur.

This guide will explain all possible solutions to encounter the above-stated error. This article’s content is as follows:

Let’s start with the first reason for the error.

Reason: Module is not installed

By default, Python language does not provide the “Pillow” library from its environment to import the “image” module. In such a case, if the “image” module is tried to be imported, then the error “import error no module named image” is displayed. The below screenshot displays the error:

Solution: Install “image” Module

The best solution is to install the image module that enables users to process images. The step-by-step procedure is given below to install the image module:

Step 1: Update Repository

First, update the core libraries of your Linux system. Different Linux distributions commands are as follows to update the repository:

For CentOS and RHEL:

$ sudo yum update

For Arch Linux:

$ sudo pacman -Syy

For Ubuntu and Linux Mint:

$ sudo apt update

Step 2: Install pip Package Manager

The next step is to install the pip package manager. Different Linux distributions commands are as follows to install manager:

For Fedora:

$ sudo dnf install python-pip

For CentOS and RHEL:

$ sudo yum install python-pip

For Ubuntu and LinuxMint: 

$ sudo apt install python3-pip

Check the Pip Version

To check the installed “pip” version in the system, the “–version” utility is used:

$ pip3 --version

The output shows that “pip 22.0.2” has been installed in the operating system.

Step 3: Install Image Module

To install the “image” module from the pip package manager, execute the below script that downloads the required module. After downloading, it installs all dependencies files in the operating system:

$ python3 -m pip install image

Check Installed Image Module

To check the installed module, the “find” command is utilized with the “name” utility that matches the “image” directory in the system:

$ sudo find ~ -name image -type d

Test the Module

You can verify the “image” module after executing the above “test.py” file which displays the error:

$ python3 test.py

The output returns the “Welcome to Python” in the terminal.

Reason 2: Pillow Library is corrupted/missing

Another reason that causes the same error is if the pillow library is corrupted and does not import the “image” module in the system.

Solution: Reinstall Pillow Library

One of the solutions to resolve the error is to reinstall the “Pillow” library that enables users to access the “image” module in the operating system. For instance, the “–force” utility forcefully installs the required library with all dependencies files:

$ pip install --upgrade --force-reinstall Pillow

After executing the command, the “Pillow-9.3.0” package has been successfully installed in the operating system.

That’s how you can fix the import error of the image module.

Conclusion

The error “import error no module named image” occurs when the library is corrupted or is not being loaded correctly to import the module. For that, the pillow library must be reinstalled. To encounter the error, first, you need to install the “pip” and then use it to get the “image” module. This post has briefly described the reasons and solutions for the error “import error no module named image” in Linux.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×