Python

No Module Named Pip

Pip is an extensive and powerful package installer for Python. Using pip, you can download and install external packages to your programs.

This article will discuss resolving a standard error you may face when using the pip package.

Python ‘no module named pip’

This error occurs when you attempt to import a module named ‘pip’ and Python cannot find it in that environment.

>>> import pip

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pip'

Fix 1 – Install the Requirements

You need to ensure a Python interpreter and pip are installed before diving into other techniques to resolve this error.

On Windows, you can download and install Python and pip using the official Python installer.

https://www.python.org/downloads/

On Linux (Debian based), open the terminal and run the commands:

$ sudo apt-get update

$ sudo apt-get install python3 python3-pip -y

The commands above should install Python 3 and pip.

On REHL systems, run the commands:

$ yum update

$ dnf update

$ yum install python3 python3-pip

$ dnf install python3 python3-pip

You can verify that Python and pip are installed by running the commands:

$ python3 –version

$ pip3 --version

The commands above should return the installed Python and Pip version.

Fix 2 – Install Pip Package

The second and most viable solution is to install the pip package. Open your terminal and run the command:

$ pip install pip

On Linux, you may need to replace pip with pip3.

Once completed, the command should install the pip library on your environment.

Note that this method is prevalent when working with minimalistic Python virtual environments.

Fix 3 – Update Path

In some instances, the error may result from an incorrect path entry. You can resolve this by adding the path to your Python executable to your environment variables.

On Windows, open your terminal window and run the command:

$ where python

The above command should return the PATH where your Python binary is installed. An example output is as shown:

To add the directory to the PATH, run the command:

$ set PATH=%PATH%;<absolute_path_to_the_python_binary>

You can replace the path to your Python binary as given from the output of the where command:

An example is as shown:

The command above should add the specified directory to the env variables.

On Linux, you can add Python to your env variables by running the command:

export PATH=”$PATH:/usr/local/bin/python”

Closing

This tutorial provides you with three main concepts you can resolve the ‘no module named pip’ error in Python.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list