Check if Python is installed
Python comes pre-installed on Raspberry Pi OS, so you typically don't need to install it manually. To verify Python is available:
- Open Terminal on your Raspberry Pi.
- Type the following command and press Enter:
python3 --version - You should see output like
Python 3.11.2or similar, showing your installed Python version.
If Python is installed (which it should be on a standard Raspberry Pi OS installation), you're ready to start coding. If you receive an error saying python3 is not found, continue to the installation steps below.
Installing Python (if needed)
If Python is not installed, follow these steps carefully:
Update your system packages:
sudo apt updateInstall Python 3 and development tools:
sudo apt install python3 python3-pip idle3 -yVerify the installation:
python3 --version
Most users won't need manual installation, as Python 3 is part of the standard Raspberry Pi OS image.
Use Python on your Pi
You can use Python in two main ways: interactively in the Python shell, or by writing and running scripts.
Python interactive shell
The Python shell (also called REPL - Read-Eval-Print Loop) lets you try Python commands immediately and see results. It's great for learning and testing ideas.
To start the Python shell, open Terminal and type:
python3You'll see the Python prompt (>>>). Try a simple command:
print("Hello, Raspberry Pi!")Press Enter to see the output. Type exit() or press Ctrl + D to leave the Python shell.
Python scripts
For anything beyond simple experiments, you'll write Python code in files (called scripts) and run them. Python script files end with .py.
Choose an IDE
While you can write Python in any text editor, using an Integrated Development Environment (IDE) makes coding much easier. An IDE provides syntax highlighting, error detection, and debugging tools.
Raspberry Pi OS includes two Python IDEs by default:
Thonny (recommended for beginners)
Thonny is designed for beginners and comes pre-installed on Raspberry Pi OS. It has a clean interface, built-in Python shell, and excellent debugging features.
To open Thonny:
- Click the Raspberry Pi menu → Programming → Thonny Python IDE
- Or run
thonnyfrom Terminal
Thonny shows your code in one pane and the Python shell in another, making it easy to write code and test it immediately.
IDLE (Python's official IDE)
IDLE is Python's built-in IDE and offers a straightforward coding environment.
To open IDLE:
- Click the Raspberry Pi menu → Programming → Python 3 (IDLE)
- Or run
idle3from Terminal
Geany (for multiple languages)
Geany is a lightweight text editor and IDE that supports many programming languages, not just Python. It's also pre-installed on Raspberry Pi OS.
To open Geany:
- Click the Raspberry Pi menu → Programming → Geany
- Or run
geanyfrom Terminal
Choose the IDE you find most comfortable. For beginners, Thonny is the best starting point.
Run Python scripts
Once you've written a Python script and saved it (for example, hello_pi.py), you can run it from Terminal:
python3 /path/to/your/script/hello_pi.pyFor example, if you saved hello_pi.py in your home directory's Documents folder:
python3 ~/Documents/hello_pi.pyThe ~ symbol is shorthand for your home directory (/home/pi by default).
Your first Python script
Try creating a simple script to test everything works:
- Open Thonny or IDLE.
- Type this code:
print("Hello from Raspberry Pi!") print("Python version:", __import__('sys').version) - Save the file as
test.pyin your home directory. - Run it from Terminal:
python3 ~/test.py
You should see output showing your message and Python version.
If it doesn't work
- python3 command not found: Ensure you're using
python3(with the 3) rather than justpython. On Raspberry Pi OS,python3is the correct command. If Python is genuinely missing, reinstall Raspberry Pi OS or usesudo apt install python3. - Permission denied when running a script: Make sure you're using
python3 script.pyrather than trying to run the script directly. Alternatively, add execute permissions:chmod +x script.py, then add#!/usr/bin/env python3as the first line of your script. - Module not found errors: If your script uses external libraries (modules not included with Python), install them with
pip3 install module-name. For example:pip3 install numpy. - IDE won't open: Try running it from Terminal (
thonnyoridle3) to see any error messages. Ensure your Raspberry Pi OS is fully updated:sudo apt update && sudo apt upgrade.
Need help with Python?
Tell us what you're trying to do, any error messages you see, and which IDE or method you're using.
Contact Vilros Support ↗