Using pip on Windows
In this resource you will learn how to use pip on Windows so that you can easily install useful Python software.
What is pip?
If you have used Python before, you may have used code similar to these examples:
from time import sleep
In the examples above, you are using code from a library written by somebody else. The libraries in the examples above are called
random and are included by default when you install Python.
However, lots of other code libraries exist, and you might want to use some of their functions in your Python programs. For example, if you want to manipulate images you might want to use
PIL, you could make games with
pygame or craft GUIs with
guizero. However, if you try to use these libraries without installing them, they won't work:
This is where you need pip. You can use pip to install Python libraries on your computer so that you can use them in your programs. You have probably seen instructions for installing Python libraries in guides on the Raspberry Pi website and on other websites. A Raspberry Pi with the standard Raspbian distribution will have pip already installed. However, if you are using a Windows computer, you may not have pip available as standard.
This resource will show you how to get pip working on a Windows computer.
Do I already have pip?
First, let's check whether you already have pip installed:
Open a command prompt by typing
cmdinto the search bar and then clicking on Command Prompt in the menu:
If you are not using your own computer at home (for example, if you are using a computer on a school network), you may not see Command Prompt appear in the menu, or you may not be allowed to open it because you don't have administrator privileges. Please speak to your network manager about whether your network allows the use of the command prompt to install Python software, as it is common for access to be blocked. If you are not permitted to use the command prompt, pass this guide to your network manager so they can install Python libraries on your behalf.
Type the following command into the command prompt and press Enter to see if pip is already installed:
If pip is installed and working you will see a version number like this.
If so, you already have pip and can install any Python module you like by typing the following into a command prompt:
pip install name-of-module
If you don't see a version number and instead get an error message, continue working through this guide.
Is Python on your PATH?
If you walked outside and found a Python on your path it would be really bad! However, we're talking about whether the location of Python is on the Windows
PATH, which is a list of places where Windows automatically looks for software.
In the command prompt, type
pythonand press the enter key. If Python is on your PATH, you should see it start up:
If you saw Python start up, skip to the next section. If you saw an error message instead, follow the steps below to add Python to your PATH.
In the Windows search bar, type in
python.exe, but don't click on it in the menu. Instead, right click on it and select Open file location
A window should open up with some files and folders: this should be where Python is installed. Right click on the address bar at the top and select Copy address as text.
Note: if the address bar contains the words Start menu, then you are probably looking at a shortcut to Python. Right-click on the file called
3.xis the version number of your Python installation) and select Open file location until you see a folder containing a file called
From the main Windows menu, open the Control Panel:
In the search box on the top right, type in
environment, then in the search results click on Edit environment variables for your account:
If there is already a variable listed called Path, click on it to select it, then click Edit.... If it does not exist, instead click New...
If your popup box looks like this, click New and then paste in the address you copied earlier. Then click New again, paste in the address again, and add
Scripts\at the end. Press OK twice to finish editing environment variables.
If your popup box has only a single line for variable value, paste in the address, type a semicolon (
;), paste in the address again, and add
Scripts\at the end. Press OK to finish editing environment variables.
If the the command prompt window is still open, close it, then re-open it. This will make sure the changes have taken effect in the command prompt you are using.
- Once again, type in
pythonat the command prompt and press the Enter key. You should now see Python start successfully. Press
cto exit the Python shell.
Now that you can use Python from the command line, you can use pip! These instructions should work for Python version 3.4 or above. If you are using an earlier version of Python, you can upgrade to a newer version from the Python website.
At the command prompt, type the following command to upgrade pip:
python -m pip install -U pip
Now you can use pip! You can install libraries using the
pip installcommand. For example, if you wanted to download the
guizerolibrary you would type this:
pip install guizero
If you use online guides, you may often see instructions for installing Python packages with pip on Linux, for example you might see this command given to install the Pygame Zero library:
sudo pip3 install pgzero
This command won't work on Windows. To convert it into a command you can use, take the name of the library and type
pip installin front of it:
pip install pgzero
Have fun using pip to install lots of new packages! Why not try these resources which require Python libraries to be installed: