Last modified: May 28, 2025 By Alexander Williams
Install Python Package on Raspberry Pi
Installing Python packages on a Raspberry Pi is simple. This guide covers different methods. You will learn to use pip
, apt
, and virtual environments.
Table Of Contents
Prerequisites
Before installing packages, ensure your Raspberry Pi is updated. Run these commands in the terminal.
sudo apt update
sudo apt upgrade
This updates the system packages. It ensures compatibility with new Python packages.
Installing Python Packages with pip
pip is the standard package manager for Python. It works well on Raspberry Pi. Use it to install most Python packages.
First, check if pip is installed. Run this command.
pip --version
If pip is not installed, install it with this command.
sudo apt install python3-pip
Now, install any package. For example, install the requests
package.
pip install requests
This downloads and installs the package. You can now use it in your Python scripts.
Installing Python Packages with apt
Some Python packages are available via apt
. These are pre-compiled for Raspberry Pi. They may work better than pip packages.
Search for a package with apt.
apt search python3-<package-name>
For example, install the numpy
package.
sudo apt install python3-numpy
This method is useful for packages with system dependencies.
Using Virtual Environments
Virtual environments keep projects isolated. They prevent package conflicts. Always use them for larger projects.
Create a virtual environment.
python3 -m venv myenv
Activate the environment.
source myenv/bin/activate
Now, install packages inside the environment.
pip install pandas
Deactivate the environment when done.
deactivate
Common Issues and Fixes
Sometimes, installations fail. Here are common fixes.
Issue: Pip installation fails with errors.
Fix: Upgrade pip and try again.
pip install --upgrade pip
Issue: Missing system dependencies.
Fix: Install the required dependencies.
sudo apt install libatlas3-base libopenblas-dev
For more complex setups, check our guide on Install Python Package in Docker.
Example: Installing a Package
Let's install the flask
package. This is a popular web framework.
First, create a virtual environment.
python3 -m venv flaskenv
source flaskenv/bin/activate
Now, install flask.
pip install flask
Verify the installation.
python -c "import flask; print(flask.__version__)"
This should print the installed version of flask.
Conclusion
Installing Python packages on Raspberry Pi is easy. Use pip
for most packages. Use apt
for system packages. Always use virtual environments for projects.
For other platforms, see our guides on Install Python Package for Azure Functions and Install Python Package in AWS Lambda.