What is modulenotfounderror: no module named ‘pip’ in Python?
The “ModuleNotFoundError: No module named ‘pip'” error message in Python occurs when pip is not installed in your Python environment.
What is a pip?
PIP is an acronym for “Pip Installs Packages”, and is a system for managing packages that are written in Python.
It comes pre-installed starting from Python version 3.4.
The following are some of the common commands you can use with PIP:
- pip –version:
Check the version of PIP installed.
- pip install:
Download and install a package named.
- pip uninstall:
Uninstall the package named.
- pip list:
List all the packages installed on your system.
How to fix Modulenotfounderror: no module named ‘pip’ in Python?
Here are some ways to fix the no module named ‘pip’ in Python error message:
Solution 1: Install pip
Ensure the pip is installed. You can use the ensurepip module which provides support for bootstrapping the pip installer into an existing Python installation or virtual environment.
Use the following command for Windows:
py -m ensurepip --upgrade
Use the following command for MacOS:
python -m ensurepip --upgrade
Use the following command for Linux:
sudo apt install python3-pip
Use the following command for Python 3:
python3 -m ensurepip --upgrade
Solution 2: Check the pip version
After the installation of the module is complete, execute any of the given commands to verify if pip is accessible.
Use the following command:
pip -V
or
pip3 -V
If pip is not available in PATH, use the following commands:
python -m pip -V
or
python3 -m pip -V
Solution 3: Alternative ways to Reinstall the pip
Try using the get-pip.py script to install the module, if the above command doesn’t work in your case.
Initially, obtain the script from the bootstrap.pypa and save it to your system.
To do this, right-click and choose the ‘Save As…’ option from the context menu.
If the previous command fails, you can attempt to reinstall pip using the following command.
python get-pip.py
For Python 3:
python3 get-pip.py
For Windows:
py get-pip.py
Solution 4: Update Path
If executing:
pip -V
is unsuccessful but:
python -m pip -V
works, it indicates that the pip path is not included in your system’s PATH.
On Windows, this can be rectified using the set PATH command.
You can determine Python’s location by using the where python command as shown below:
$ where python
Output:
C:\Users\Windows>where python
C:\Users\Windows\AppData\Local\Programs\Python\Python310\python.exe
C:\Users\Windows\AppData\Local\Microsoft\WindowsApps\python.exe
To include the directory in the PATH, execute the following command:
set PATH=%PATH%;C:\Users\Windows\AppData\Local\Programs\Python\Python310
This should enable the command prompt to locate the pip module for the ongoing session.
If you wish to permanently include the location in the PATH, opt for the setx command in place of set.
For Linux and macOS, you can add Python in your env variables by executing the export PATH command along with the $PATH variable:
export PATH="$PATH:/usr/local/bin/python"
Please replace Python with python3 or py depending on your system and Python version.
If you encounter permission issues, you might need to prefix the commands with sudo on Linux or macOS, or run the command prompt as an Administrator on Windows.
Remember to replace Python and pip with the correct version if you have multiple versions of Python installed, such as python3 or pip3.
If none of these solutions work, it might be helpful to uninstall and reinstall Python.
Conclusion
The “ModuleNotFoundError: No module named ‘pip'” error message in Python occurs when pip is not installed in your Python environment.
To fix this error, Ensure the pip is installed in your Python env.
By following the guide above, there’s no doubt that you’ll be able to resolve this error quickly.
We hope that you’ve resolved the error with the help of this guide. Thank you for reading, and have fun coding!