Concept Tutorials

Python Libraries Every Developer Needs to Know for Raspberry Pi

Getting Started with Python on the Raspberry Pi

Python runs natively on the Raspberry Pi, and that’s a big part of why the Pi is so much fun to tinker with. You can control hardware and software with a few plain-English commands. The syntax is clean enough that beginners pick it up fast, so writing code to read a sensor or fire off a script doesn’t take long.

Using Thonny IDE

The quickest way to start writing Python on the Pi is Thonny, the built-in Python3 editor. Open it from the desktop or the applications menu and you’ll land on the REPL (Read-Evaluate-Print-Loop), a prompt where you type commands and get answers back right away. It’s interactive, so you see the output on screen the moment you hit enter. The Shell window makes quick tests painless.

What Python Libraries Actually Do for You

Python libraries are bundles of ready-made functions, so you don’t have to write everything from scratch. There are more than 137,000 of them out there, covering machine learning, data science, data visualization, and plenty more. They cut down the work, which is exactly what you want on a Raspberry Pi project.

Installing Python Libraries with apt

Some packages already live in the Raspberry Pi OS archives. Grab those with apt. Like this:

sudo apt update sudo apt install python-picamera 

Updating those same modules later is just as quick:

sudo apt update sudo apt full-upgrade

Installing with pip

Not everything lives in the Raspberry Pi OS archives, and the versions that do can lag behind. When that happens, pull the package straight from the Python Package Index (PyPI).

See also  How to Troubleshoot Common Arduino Errors

First, install pip:

sudo apt install python3-pip

Then install what you need with pip3. For example:

sudo pip3 install simplejson

What is piwheels?

Some Python packages have to compile before they’ll run, and that crawls on older Pi models. piwheels fixes that with pre-compiled packages (wheels) you can drop straight in. Raspberry Pi OS already points pip at piwheels out of the box, so you get the speed-up for free. Want the details? Head to piwheels.org.

Libraries That Ship with Raspberry Pi OS

The standard Raspberry Pi OS comes with a stack of pre-installed libraries already. Want to see the full list? Open Thonny, click Tools, then Manage Packages. They’re built in, so you can start using them right away.

These are the ones for driving GPIO pins and hardware:

  • GPIO and Hardware Control Libraries
    • RPi.GPIO
    • RPIO.GPIO
    • wiringPi
    • pigpio
    • gpiozero

Picamera lets you connect and control a CSI camera from Python.

  • Camera Interface
    • Picamera

Raspberry Pi OS also packs some heavy hitters for data and AI work:

  • Data Science and Machine Learning
    • Sci-kit-learn
    • NumPy
    • OpenCV
    • SciPy
    • TensorFlow
    • Pandas
    • Matplotlib

Need to pull data off the web and parse it? These have you covered:

  • Web and Networking
    • Requests
    • BeautifulSoup
    • Scrapy
    • SQLAlchemy

Feel like building a small game or a graphics app? Reach for these:

  • Graphics and Games
    • Pygame
    • Pillow (image processing)

And Raspberry Pi OS throws in a bunch of handy built-in Python modules too:

  • Built-In Python Modules
    • csv
    • random
    • collections
    • datetime
    • re (for regular expressions)
    • math

Frequently Asked Questions

What does this Python Libraries Every Developer Needs to Know for Raspberry Pi tutorial cover?

Introduction to Python on Raspberry Pi Python is an easy-to-use programming language that works natively on the Raspberry Pi .

Which Raspberry Pi model fits the Python Libraries Every Developer Needs to Know for Raspberry Pi project?

Pi 4 (4GB) or Pi 5 for desktop apps and AI workloads. Pi Zero 2 W is enough for headless / sensor builds. Pi 3 B+ works but is slower for camera or ML.

How do I auto-start the Python Libraries Every Developer Needs to Know for Raspberry Pi script on boot?

Use systemd. Create /etc/systemd/system/myproject.service with ExecStart=/usr/bin/python3 /home/pi/script.py and Restart=always. sudo systemctl enable myproject.

// written by Ruzell Ramirez

Ruzell Ramirez writes the Arduino, ESP32, and Raspberry Pi tutorials at Circuitrocks Learn. Background in embedded electronics and microcontroller projects, with a soft spot for schematic-level explanations and beginner-friendly project builds. Based in the Philippines. When a tutorial here goes deep on power-supply quirks or USB-to-serial gotchas, that's usually him talking.