Python No Module Named PIP [FIXED]

Python No Module Named Pip [fixed]

Python comes with a lot of standard library. It is more than enough to use for every standar task like mathematical operation. However, with so many needs to create non-standard application, developers need more modules to enrich functionality of Python software. PIP itself is a Python module manager. It is like APT for debian. The difference is, Python is treated as if it is an operating system and PIP is the (modules) package manager. So It is not a module.

Intallation of PIP Package Manager

Installation of Python PIP package manager takes several steps. Here you are.

On Windows Machine

In Windows operating system, Python is not installed by default. To install Python, we need to download Python software from its offical Python website.

When the Windows download page is open, choose the latest stable version. Python for Windows comes with PIP installed. Install it by double clicking. Here, we need to reconfirm once again that is not a module but a manager for modules package. When the installation finished, we could try the following command on Windows PowerShell:

python -m pip install SomeModulePackage

On Linux and MacOS Machines

On Linux, Python 3 already installed by default. However, always check and re-check. Here the command to check it:

python3 --version

Make sure that the return of the command as follow:

Python 3.10.6

Otherwise, Python has not been installed yet.

Next, try to check whether PIP is installed:

python3 -m pip --version

Here, you will got message that no module named pip as the main topic of this article.

/usr/bin/python3: No module named pip

That is why people call this as an ‘no module error message’. That is happen because pip can be a name of a module we create and the official Python does not create any module with pip as a name. As we talk in the beginning it is a module package manager.

To install PIP package manager, please download from the official here.

Make the file executable by the following command:

chmod +x get-pip.py

Then execute the script by the following command:

./get-pip.py

On the first occation, there will an unexpected error like the following:

/usr/bin/env: ‘python’: No such file or directory

This is because the file get-pip.py is a general installation file. The user of the file is assumed as an advanced user who knows how to fix this. On a Python script, the first row is begin with where the interpreter of the script located. The /usr/bin location is a general default location. In Linux, with so many distributions, there are a plenty of variation of location where executable programs are. So, developers who want to install it, need to adjust the location of Python3. Open the get-pip.py file and change the first row to where Python3 installed.

First, check where it is located by listing the content of /usr/bin directory:

ls /usr/bin

This command will return list of available programs that are installed in the operating system. Take a look at the list. Make sure that there is python3.

After that, open the get-pip.py file and change the first row #!/usr/bin/env python to:

#!/usr/bin/python3

Env means environtment, that is, location of our Python3 interpreter.

After changing this, re-execute command for get-pip.py scripts. You would get message like this:

Collecting pip
  Downloading pip-22.3.1-py3-none-any.whl (2.1 MB)

It means, the installation of PIP modules-package-manager is in progress. Please note that it is installing to your /.local/bin of your home directory. If you have not changed the environtment path, you could move to that directory with cd command:

cd /home/your-home-directory/.local/bin

Then, list the content of the directory by ls command:

ls

Then you would get return of the directory content as follow:

pip  pip3  pip3.10  wheel

Now, try to check the version of PIP once again

./pip --version

This command would return result as follow:

pip 22.3.1 from /home/home-directory/.local/lib/python3.10/site-packages/pip (python 3.10)

Now, we try to install a module with PIP package manager, for a module. We are still on ../.local/bin directory with the environtment path has not been set up yet. So, to use PIP package manager, we are going to execute it like the following:

./pip install package-name

In the command above there is install. Install is one of available command within PIP. To know other commands, simply type pip without any command or options:

./pip

This will return all of commands and options available in PIP.

Now, we are going to test the function of PIP package manager by installing one of the most popular package written in Python; Pandas:

./pip install pandas

Here you will get return like this:

Collecting pandas
  Downloading pandas-1.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.1 MB)...
...
Successfully installed pandas-1.5.1 python-dateutil-2.8.2 pytz-2022.6

Last, we need to link pip in our local directory to /usr/bin:

sudo ln -s /home/home-directory/.local/bin/pip /usr/bin

Now , we can execute PIP anywhere:

python3 -m pip --version

Steps for Installing PIP Package Manager

  • Check whether Python is installed. With the new version of Python3 and Python2 that is still available, a developer must check with specific command, that is, python3 or python2. It is often that python only is not working.
  • Check whether PIP package manager installed or not
  • If not, download from the official Python website

I used to be a pilot, but ended up being just a mediocre writer.

×