How To Install Python Modules on Raspberry Pi 5 and Earlier Models

Python Modules
(Image credit: Tom's Hardware)

The Raspberry Pi 5 requires a new version of Raspberry Pi OS which is based on Debian 12 “Bookworm.” If you’re burning a new card for a Raspberry Pi 4, Pi 3, Pi Zero or other, you will probably also be using Bookworm. This new version of the OS changes how Python modules are installed, and at first it can be quite confusing. You will almost certainly need to install Python modules to program any HATs, including the best Raspberry Pi HATs, so this matters a lot.

Python virtual environments are a handy way to keep your Python projects contained and away from your operating system’s default Python installation. In the past we installed Python modules at an OS level and for many of us this worked well, but we always ran a risk of breaking our OS install. There is always a chance that a Python module installed via the Python package manager, pip, would conflict with one installed using the OS’ package manager (in this case APT).

Latest Videos FromTom's Hardware
Les Pounder
Associate Editor

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".