0
0
Iot-protocolsHow-ToBeginner · 3 min read

How to Install Python Packages on Raspberry Pi Easily

To install Python packages on Raspberry Pi, use the pip command in the terminal, like pip install package_name. For Python 3, use pip3 install package_name to ensure the package installs for Python 3.
📐

Syntax

Use the pip tool to install Python packages. The basic syntax is:

  • pip install package_name - installs a package for Python 2 (if installed).
  • pip3 install package_name - installs a package for Python 3, which is the default Python on Raspberry Pi OS.
  • You can add --user to install packages only for your user without needing admin rights.
bash
pip3 install package_name
💻

Example

This example shows how to install the popular requests package for Python 3 on Raspberry Pi.

bash
pip3 install 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
⚠️

Common Pitfalls

Some common mistakes when installing Python packages on Raspberry Pi include:

  • Using pip instead of pip3 when Python 3 is needed, causing packages to install for Python 2 or fail.
  • Not having pip3 installed. You can install it with sudo apt update && sudo apt install python3-pip.
  • Trying to install packages without sudo when system-wide installation is needed, leading to permission errors.
  • Not updating pip itself, which can cause installation errors. Update with pip3 install --upgrade pip.
bash
Wrong:
pip install requests

Right:
pip3 install requests
📊

Quick Reference

CommandDescription
pip3 install package_nameInstall a package for Python 3
pip3 install --user package_nameInstall package for current user only
sudo apt update && sudo apt install python3-pipInstall pip3 if missing
pip3 install --upgrade pipUpdate pip to latest version
pip3 uninstall package_nameRemove a package

Key Takeaways

Use pip3 to install Python packages for Python 3 on Raspberry Pi.
Install python3-pip via apt if pip3 is not available.
Use sudo for system-wide installs or --user for user-only installs.
Keep pip updated to avoid installation issues.
Check Python version and pip version to ensure correct package installation.