Interesting question. How does one run Python on a Raspberry Pi? The Raspberry Pi is a small, affordable, and highly customizable computer that can run a full Linux operating system. Python, being one of the most versatile and popular programming languages, is often the go-to choice for coding on this little board.
This guide provides a complete, step-by-step overview of running Python on a Raspberry Pi. Let’s start with some foundational steps.
Breaking Down the Problem
Here’s what we need to consider when running Python on a Raspberry Pi:
- Pre-installed Python: Does the Raspberry Pi come with Python pre-installed?
- Accessing Python: How do I access Python on the Raspberry Pi?
- Python Versions: Which versions of Python are typically available on the Pi?
- Running Scripts: Can I run Python scripts directly from the terminal, or do I need a specific development environment?
- Upgrading Python: What if I want to update or install a different version of Python?
- Additional Packages: Are there any extra packages or tools required?
We’ll assume you’re using Raspberry Pi OS (formerly Raspbian), the most common operating system for the Raspberry Pi.
Step 1: Does Raspberry Pi Come With Python Pre-Installed?
Yes, Raspberry Pi OS comes with Python as a pre-installed software. In fact, it includes both Python 2 and Python 3 by default. However, since Python 2 has reached its end of life, you should focus on Python 3.
Step 2: Checking if Python is Installed
To confirm whether Python 3 is installed and to see which version you have, open the terminal and run:
python3 --version
You should see output similar to:
Python 3.9.2
(The actual version may differ depending on your Raspberry Pi OS.)
Step 3: Running Python in the Terminal
Once you’ve confirmed Python is installed, you can start the Python interpreter by typing:
python3
You’ll see something like:
Python 3.9.2 (default, Feb 28 2023, 11:30:45) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
This is the interactive Python shell, indicated by the >>>
prompt.
Step 4: Running a Python Script
To run a pre-written Python script:
Create a new Python file (e.g., hello.py
) using a text editor such as Nano:
nano hello.py
Write your Python code in the file. For example:
print("Hello, Raspberry Pi!")
Save and exit Nano by pressing CTRL + O
(then Enter) and CTRL + X
.
Run the script with:
python3 hello.py
You should see the message Hello, Raspberry Pi!
displayed in the terminal.
Step 5: Installing Additional Python Packages
Many Python projects require additional libraries. You can install these using pip, the Python package manager. First, check if pip is installed:
pip3 --version
If it’s not installed, you can install it by running:
sudo apt update sudo apt install python3-pip
Once pip
is installed, use it to install packages. For example, to install the requests
library:
pip3 install requests
Step 6: Using an IDE (Optional)
If you prefer not to use the terminal, Raspberry Pi OS includes the beginner-friendly Thonny IDE. You can open Thonny by navigating to:
Menu > Programming > Thonny Python IDE
You can then write your code in Thonny’s editor and run it by clicking the Run button.
Step 7: Updating Python (Optional)
If you want a newer version of Python than what’s included by default, first make sure your system is up to date:
sudo apt update sudo apt upgrade sudo apt install python3
For versions not available via the package manager, you’d need to compile from source—an advanced topic that goes beyond the scope of this beginner guide.

Let’s Recap
Check if Python is installed:
python3 --version
Run Python in the terminal:
python3
Run a Python script:
python3 hello.py
Install additional packages:
pip3 install <package_name>
Use an IDE:
Thonny is a beginner-friendly IDE included with Raspberry Pi OS.
Update Python:
sudo apt update sudo apt upgrade sudo apt install python3
That’s it! You now have a foundational guide to getting started with Python on a Raspberry Pi. From here, you can explore virtual environments, GPIO control, and more advanced projects as you become more comfortable.