This can be solved by installing pip, here is how you do it:
For mac, apt-get is not supported so we can install using brew instead:
Pip is standard with Python 2.7.9+ and Python 3.4+.
This error message has nothing to do with your coding ability, and everything to do with something not correctly configured or installed on your system.
Below we will provide a few additional methods to solve this kind of error.
We are first going to understand what Python modules and packages are. Then we are going to explore some methods of solving the “no module named PIP” error.
Concepts to understand
You need to understand certain fundamental concepts before you try to solve an error. Otherwise, you will not be able to accurately diagnose and troubleshoot the problem. We are briefly going to explore modules, packages, and PIP.
There comes a time when writing out code line by line is no longer sustainable. If you are creating a program that requires the same lines of code, writing out the entire code is not efficient.
Creating files of regularly used code and plugging them in when needed is a time effective way of programming.
In addition, many brilliant programmers have compiled files of code you can simply plug into your own program, saving you time and effort. This means you do not have to understand every single concept behind connecting and working with a database, because there is already a Python file (several in fact) where most of the work has already been done for you.
These code files are known as modules. You can also create your own if you want to.
Simply save a file with the extension .py, and import it into your current file. Here is an example of how this works:
print (“Hello there. How are you doing?”)
Now imagine you have multiple files where you need to greet users. You could reuse the above code without rewriting the print statement dozens of times. For example:
Putting that line at the top of your file makes all the functions and variables defined in greetings.py available in morning.py file.
While this is a very simple example, think of more complicated scenarios. What if you had to type in the same code hundreds of times for your website’s navigation and footer for every page? This would quickly become unmanageable.
Packages are collections of modules. Related modules can be grouped under a single package.
For example, if you are working with a database, you can group various modules that do the following into a single package:
- connect to the database
- close off connection to the database
- retrieve records from a table
- delete records
- update data
Downloading every single module you need, manually installing it, updating it, and configuring it to work on your machine can quickly become complicated. That is why we have package managers to do the heavy lifting for us. All you need to do is type in a line or two of instructions, and a package manager handles everything else.
Package Installer for Python (PIP) is the most recommended Python package manager.
The PIP package manager is included by default if you are running Python 3.4 and above.
Here is an example that demonstrates the power of the PIP package manager.
Django is a popular framework for Python web developers. If you want to install Django, you could download the source files, unzip them, manually drop them in the correct directories on your machine, and configure everything that needs to be configured on your own.
Or, you could simply type the following PIP command in your command line:
py -m pip install Django
You can then go and grab a cup of coffee while that one line downloads, installs, and configures Django for you.
No module named pip
“No module named PIP” means exactly what the error message says. The machine cannot detect a module called PIP.
There are two main reasons you are getting this kind of error.
It is possible PIP has not been installed on your machine. This is most likely the case if your Python version number is lower than 3.4.
Otherwise, something has not been correctly configured on your machine.
There are a few reasons why you might be getting a “no module called PIP” error. We have listed some of them along with solutions below.
It is important to establish if Python is installed on your machine in the first place. Python is already installed if you are using a Mac. So the following steps are going to focus on Windows.
Go to the command prompt. The quickest way of finding it on Windows is to:
- Press the Windows key to go to the search box.
- Type in CMD.
- Enter on command prompt.
Type in the word “python” in command prompt. If Python is installed, an environment will open on the command line. You will get a screen that displays information such as:
Microsoft Windows [Version 10.0.22000.978] “(c) Microsoft Corporation. All rights reserved. C:\Users\Tawanda>python Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>”
On the other hand, the following message will be displayed if Python is not installed:
“'python' is not recognized as an internal or external command, operable program or batch file.”
Visit the following page to download Python: https://www.python.org/downloads/.
Open the .exe file when download is complete. Follow all instructions when you are prompted by the installer.
Just like we did with Python, you first want to check if PIP is installed. This is especially true if your Python version is below 3.4.
Go to command prompt on Windows or terminal on Mac. Type in the following command:
The following message, or one like it, will be displayed if you already have pip installed:
“pip 22.1.2 from C:\Python38\lib\site-packages\pip (python 3.8)”
The following will be displayed if PIP cannot be found on your system:
“pip is not recognized as an internal or external command, operable program or batch file.”
Follow these steps to install PIP:
- Download the get-pip.py file from https://pypi.org/project/pip/.
- Move get-pip.py to the directory containing your Python installation.
- Press ctrl + L (Windows) inside the directory containing get-pip.py.
- Type “cmd” in the address bar, which will open up the command prompt in the correct directory.
- Type in “python get-pip.py”.
- Wait until you see a message that goes something like: “Successfully installed pip-“.
- Type in “pip –version” to check if PIP has been successfully installed.
Update Windows Environment Variables
Environment variables are a special feature of Windows. They help programs know where to access and store files. Your machine needs to be able to find PIP in order for Python to make use of it. As a result, PIP needs to be added to your environment variables.
Follow these steps to add PIP to your Windows machine’s environment variables:
- Copy the path to the directory where PIP is saved – you can access this by pressing ctrl + L when inside the relevant directory, which will select the directory path, and all you have to do is hit ctrl + C.
- Click the Windows button to go to the search box.
- Type in “View Advanced system settings” and enter.
- Select Environment Variables.
- Go down to Variable Path.
- Click new.
- Add the directory path you copied in step 1.
Update Python interpreter
An update / upgrade of your existing installation of Python might be in order if your problem is being caused by compatibility issues.
Download the latest version of Python from https://www.python.org/.
Let the installer run and follow whatever instructions are prompted.
Use the following command to check if Python has been updated:
Pip is always receiving updates and upgrades. It is possible your problems are being caused by a lack of compatibility between PIP, your version of Python, the operating system, or the machine itself.
Type the following command in your command prompt to upgrade PIP:
python -m pip install -U pip
The above will install the latest version of PIP.
If you are facing a backwards compatibility problem, try the following to install an older version of PIP:
The above will install PIP 2.1. Just replace the number after == with your preferred version.
Rather than spend hours configuring various files, you can simply run PIP and let the package manager do all the heavy lifting.
“No module named PIP” simply means your machine failed to detect Python’s most trusted package manager. The reasons this might occur include:
- You do not have Python and / or PIP installed.
- PIP has not been added to the environment variables.
- Your Python and / or PIP versions need updating.