How to install pip on the Raspberry Pi

In this tutorial, we will be showing you how to install pip on the Raspberry Pi.

Raspberry Pi install pip

pip (Package Installer for Python) is the package manager for Python that allows you to very easily install extra libraries and modules for you to use within your Python scripts.

We often use pip within our Raspberry Pi projects as it greatly simplifies the process for the end user. For example, instead of downloading a file and moving it to a correct location, pip handles this entire process.

You can think of pip much like the apt package manager but purely for dealing with Python.

Over the next section, we will show you how to install the pip package manager and utilize it to install a Python package to your Raspberry Pi.

Equipment

In this tutorial, we will be showing you how to install pip on the Raspberry Pi.

Recommended

Optional

This tutorial was last tested on a Raspberry Pi 400 running the latest version of Raspberry Pi OS Bullseye.

Installing pip on the Raspberry Pi

Since pip is a crucial part of using Python, it is very easily installed onto the Raspberry Pi. In this section, we will install pip from the official package repository.

To install pip, we will be using the terminal. If you are using a desktop version of the operating system, you can open the terminal by pressing CTRL + ALT + T.

1. Before installing pip, we need to update the package list and upgrade any out-of-date packages.

We can use the apt package manager to perform tasks by using the following command.

sudo apt update
sudo apt upgrade

2. Once the update completes, we can install pip to the system.

To install pip on your Raspberry Pi, you must use the following command within the terminal.

sudo apt install python3-pip

We are specifically installing pip for Python 3. Since Python 2 has been deprecated for some time, it is no longer included within the Raspberry Pi Bullseye package repository.

3. It is possible to verify that you have pip installed on your Raspberry Pi by using the following command in the terminal.

This command makes a call to “pip” and asks it to print out its version. You can also use “pip3” if you want to be confident you are using the Python 3 version of pip.

pip --version

Using pip on the Raspberry Pi

Now that you have installed pip to your Raspberry Pi, we can show you how to utilize this tool on your system.

Within the following sections, you will see how you can use pip to install, uninstall and upgrade Python modules.

Installing a Python Module using pip

pip makes the process of installing a Python module a straightforward process.

For this process to work, the module you want to install will have to be available PyPi (Python Package Index) or piwheels (pre-compiled Python packages for the Raspberry Pi).

You only have to use the following command to install a Python package to your Raspberry Pi. Just replace “MODULENAME” with the name of your module.

sudo pip install MODULENAME

For example, if you wanted to install the “gpiozero” python module, you would utilize the following command.

sudo pip install gpiozero

Uninstalling a Python module on your Raspberry Pi using pip

You can also use pip to uninstall a Python library off your Raspberry Pi. Uninstalling is useful when you have a library that you no longer require and need to save space on your device.

The only thing you need to know is the name of the module that you want to uninstall.

With the module name on hand, you only need to use “pip“, followed by “uninstall“, then finally, the module name.

sudo pip uninstall MODULENAME

For example, to uninstall a Python package called “gpiozero“, you would use the command below within the terminal.

sudo pip uninstall gpiozero

Updating a Python Module using pip

Unlike using the apt package manager, you can’t just run a single command to upgrade all of your Python modules.

Instead, you will need to know the name of the Python library you want to upgrade.

To update a Python module using pip on the Raspberry Pi, you will need to use the following command. First, ensure you replace “MODULENAME” with the module you want to upgrade.

sudo pip install --upgrade MODULENAME

For example, to update the “gpiozero” Python package on our Raspberry Pi, we would use the command below in the terminal.

sudo pip install --upgrade gpiozero

Using pip to List installed Python Modules on the Raspberry Pi

If you want to see all of the Python modules installed on your Raspberry Pi, then you can use pip’s list command.

All you need to do is utilize the following command, which will print out every installed Python module alongside its version number.

sudo pip list

After running the above command, you should see a list like the one shown below.

Package           Version
----------------- ---------
arandr            0.1.10
astroid           2.5.1
asttokens         2.0.4
automationhat     0.2.0
beautifulsoup4    4.9.3

Conclusion

In this tutorial, we have shown you how you can install and use pip on the Raspberry Pi.

pip is a crucial tool to learn how to use if you are interested in using the Python language. It allows you to install and maintain Python modules on your system quickly.

Please comment below if you have trouble using pip on your system.

Be sure to check out our many other Raspberry Pi guides and explore our Python tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *