ModuleNotFoundError: No module named ‘pip’ in Python

PIP is a widely used Python package manager to manage and perform various operations. For instance, installing, removing, upgrading, and downgrading specific packages in Python.

However, if this module is not correctly installed in the system, the error named “ModuleNotFoundError” occurs in Python.

This write-up will explain the possible reasons and appropriate solutions for the “no module named pip” error in python using the following snippet:

Reason: pip Not Installed

A common reason for the “ModuleNotFoundError: No module named pip” in Python is that the “pip” is not installed in the Python environment. The snippet below shows the stated error:

The above snippet shows that the “pip” module is not installed in our system.

Solution 1: Install pip Using ensurepip Command (Windows)

Open the command prompt and enter the following command to install the pip package:

> py -m ensurepip --upgrade

The below snippet shows that the pip version “21.2.3” has been successfully installed:

Solution 2: Install pip Using get-pip.py (Windows)

We can also install pip in our system using the bootstrapping logic method. For this, open the command prompt terminal and type the following command to download the “get-pip.py” file:

> curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

After downloading the “get-pip.py” file, the next thing is to install pip on windows using the given below command:

> python get-pip.py

As you can see in the below snippet, the “pip-22.3.1” latest version installed in Python successfully:

Verify the Installation of pip (Windows)

In our system, we can check whether pip is correctly installed. First, enter the Python shell using the “python” command in CMD and after that, run the “import pip” command:

> python
>>> import pip

Solution 3: Installing pip on Linux

To install Python pip on “Ubuntu 22.04” you can follow the given below detailed tutorial: How to Install Python Pip on Ubuntu 22.04

To install Python pip on various other Linux distributions, for example, to install Python pip on Arch Linux type the given below commands in the terminal:

# Python 2
$ sudo pacman -S python2-pip
# Python 3
$ sudo pacman -S python-pip

To install Python pip on Fedora, type the following command:

# Python 2
$ sudo dnf install python-pip
# Python 3
$ sudo dnf install python3

Similarly to install Python pip package manager on CentOS and RHEL use the given below command:

$ sudo yum install epel-release       #enabling the repository
$ sudo yum install python-pip

How to Upgrade the pip Version?

To upgrade the pip package in the system, the first step is to check the current version of the “pip module” by typing the following command:

> pip --version

The above snippet shows that the pip version “22.3.1” is installed in our system.

To upgrade the pip package in Python, the following command is used in Python:

> python -m pip install --upgrade pip

From the above snippet, it is verified that the “pip” package installed in our system is up to date.

How to Downgrade the pip Version?

To downgrade or install the specific pip version, we use the following command in terminal windows (command prompt):

> python -m pip install pip==18.1

As we can see from the below snippet that version “18.1” is successfully installed. The previous version was successfully removed from the system:

Conclusion

The “ModuleNotFoundError: No module named pip” occurs in Python when the “pip” package is not installed in our system. To rectify this error, various methods are used to install “pip” such as using the official Python installer, using the “ensurepip” command, and using get-pip.py. The various solutions for installing pip in different Linux distributions are also provided in this article. Apart from that, the methods to upgrade or downgrade the pip version is also provided.