0
0
Iot-protocolsHow-ToBeginner · 3 min read

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 pip instead of pip3, which may install packages for Python 2 (usually not installed by default).
  • Not updating pip before installing packages, which can cause errors.
  • Running pip3 commands without sudo when 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

CommandDescription
pip3 install package_nameInstall a Python package
pip3 uninstall package_nameRemove a Python package
pip3 listList installed packages
pip3 show package_nameShow package details
python3 -m pip install --upgrade pipUpdate 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.