How to Use pip on Raspberry Pi: Install and Manage Python Packages
To use
pip on Raspberry Pi, open the terminal and run pip3 install package_name to install Python packages. Use pip3 for Python 3, which is the default on Raspberry Pi OS.Syntax
The basic syntax to use pip on Raspberry Pi is:
pip3 install package_name: Installs a Python package.pip3 uninstall package_name: Removes a Python package.pip3 list: Shows all installed packages.pip3 show package_name: Displays details about a package.
Use pip3 because Raspberry Pi OS uses Python 3 by default.
bash
pip3 install package_name pip3 uninstall package_name pip3 list pip3 show package_name
Example
This example shows how to install the requests package, verify it is installed, and then uninstall it.
bash
pip3 install requests pip3 list | grep requests pip3 uninstall -y requests
Output
Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
Installing collected packages: requests
Successfully installed requests-2.31.0
requests 2.31.0
Uninstalling requests-2.31.0:
Successfully uninstalled requests-2.31.0
Common Pitfalls
Common mistakes when using pip on Raspberry Pi include:
- Using
pipinstead ofpip3, which may install packages for Python 2 (usually not installed by default). - Not updating
pipbefore installing packages, which can cause errors. - Running
pip3commands withoutsudowhen system-wide installation is needed.
Always check your Python version with python3 --version and update pip with python3 -m pip install --upgrade pip.
bash
python3 -m pip install --upgrade pip sudo pip3 install package_name
Quick Reference
| Command | Description |
|---|---|
| pip3 install package_name | Install a Python package |
| pip3 uninstall package_name | Remove a Python package |
| pip3 list | List installed packages |
| pip3 show package_name | Show package details |
| python3 -m pip install --upgrade pip | Update pip to latest version |
Key Takeaways
Use pip3 on Raspberry Pi to manage Python 3 packages.
Always update pip before installing new packages.
Use sudo with pip3 for system-wide package installation.
Check installed packages with pip3 list.
Avoid using pip alone as it may target Python 2.