Sunteți pe pagina 1din 9

11/10/2018 Using pip on Windows | Raspberry Pi Projects

Projects

Using pip on Windows


Learn about installing Python software on Windows
with pip

Python

Step 1 What you will make

In this resource you will learn how to use pip on Windows, so that you can
easily install useful Python software.

What you will learn

By following this guide you will learn:

What is pip?
How to add Python to your path
How to use pip to install Python packages on Windows

Step 2 What you will need

Hardware

Computer running Windows

Step 3 What is pip?

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 1/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

If you have used Python before, you may have used code similar to this:

from time import sleep

Or perhaps this:

import random

In the examples above, you are importing a module in order to use code
written by somebody else. The modules in the examples are called time
and random , and are included by default when you install Python.

However, people have written lots of other Python modules, 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 , or you could
make games with pygame , or craft GUIs with guizero . However, if you
try to use these modules without installing them, they won’t work:

This is where pip comes in. To be able to use use external Python modules
in your programs, you can use the pip tool to install them on your
computer. (You have probably already seen instructions for installing
Python modules with pip in guides on the Raspberry Pi website and on
other websites.) A Raspberry Pi with the standard version of Raspbian has
pip already installed. However, your Windows computer may not have pip
on it yet. Let’s change that!

Step 4 Do I already have pip?

First, let’s check whether you already have pip installed:

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 2/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

Open a command prompt by typing cmd into the search bar in the
Start menu, and then clicking on Command Prompt:

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. In that case, please
speak to your network manager about whether your network allows the
use of the command prompt to install Python software. If you are not
permitted to use the command prompt, pass this guide to your network
manager so they can install Python modules on your behalf.

Type the following command into the command prompt and press Enter
to see if pip is already installed:

pip --version

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 3/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

If pip is installed and working, you will see a version number like this:

If you do, you’re ready to use pip to install any Python module you like
by typing the following into a command prompt (replace name-of-
module with the name of your module):

pip install name-of-module

If you don’t see a version number and instead get an error message,
continue working through this guide.

Step 5 Is Python in your PATH ?

If you walked outside and found a python on your path, that would be
really bad! However, we’re talking about whether the location of Python is
in the Windows PATH , which is the list of places where Windows
automatically looks for software.

In the command prompt, type python and press Enter. If Python is in


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 le location

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 4/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

A window will open up with some les 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 le called
Python 3.x (where 3.x is the version number of your Python
installation) and select Open le location until you see a folder
containing a le called python.exe .

From the main Windows menu, open the Control Panel:

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 5/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

In the search box on the top right, type in environment , and 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 pop-up box looks like the image below, click New and then paste
in the address you just copied. Then click New again, paste in the
address again, and add Scripts\ at the end. Click OK twice to nish
editing your environment variables.

If your pop-up box has only a single line for the variable value, paste in
the address, type a semicolon ( ; ), then paste in the address again and
add Scripts\ at the end. Click OK to nish editing environment
variables.

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 6/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

If the the command prompt window is still open, close it and re-open it.
This will make sure the changes have taken e ect in the command
prompt you are using.

Once again, type in python at the command prompt and press the
Enter key. You should now see Python start successfully. Press Ctrl + c
to exit the Python shell.

Step 6 Using pip

Now that you can use Python from the command line, you can use pip! The
following instructions should work for Python version 3.4 and above. If you
are using an older version of Python, you can upgrade Python via the
Python website (https://www.python.org/downloads/).

In the command prompt window, type the following command to


upgrade pip:

python -m pip install -U pip

Now you can install modules using the pip install command. For
example, if you wanted to download and install the guizero module,
you would type this:

pip install guizero

If you use online guides, you might often see instructions for installing
Python packages with pip on Linux. For example, you might see this
command to install the Pygame Zero module:

sudo pip3 install pgzero

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 7/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

This command won’t work on Windows. To convert it into a command


you can use, take the name of the module and type pip install in
front of it:

pip install pgzero

Other pip commands

There is comprehensive documentation for pip at pip.pypa.io (https://pip.


pypa.io) — here are a few useful commands:

Upgrade an already installed module:

pip install --upgrade name_of_module

Uninstall a module:

pip uninstall name_of_module

List installed modules:

pip list

Step 7 What next?

Have fun using pip to install lots of new packages! Why not try these
resources, which require Python modules to be installed:

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 8/9
11/10/2018 Using pip on Windows | Raspberry Pi Projects

Getting started with GUIs (https://projects.raspberrypi.org/en/pro


jects/getting-started-with-guis)
Getting started with the Twitter API (https://projects.raspberrypi.o
rg/en/projects/getting-started-with-the-twitter-api)
Shakespearean insult generator (https://projects.raspberrypi.org/
en/projects/shakespearean-insult-generator/)

Published by Raspberry Pi Foundation (https://www.raspberrypi.org) under a Creative Commons license (ht


tps://creativecommons.org/licenses/by-sa/4.0/).
View project & license on GitHub (https://github.com/RaspberryPiLearning/using-pip-on-windows)

https://projects.raspberrypi.org/en/projects/using-pip-on-windows/print 9/9

S-ar putea să vă placă și