The Raspberry Pi’s default repositories may not include the latest Python version. To get Python 3.12.8, you can build it from source. Here’s how to do it.
Step 1: Prepare Your System
Update your system and install necessary dependencies for building Python.
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev \
libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
Step 3: Extract and Navigate
Extract the downloaded archive and move into the directory:
tar -xvzf Python-3.12.8.tgz
cd Python-3.12.8
Step 4: Build and Install Python
Configure the build environment and compile Python:
./configure --enable-optimizations
make -j$(nproc) # Compiles using all available CPU cores
sudo make altinstall # Installs without overwriting the default Python
Step 5: Verify Installation
Check the installed version to confirm the installation:
python3.12 --version
You should see Python 3.12.8
as the output.
Step 6: Optional — Set as Default Python
If you want Python 3.12.8 to be the default version, update the symbolic links:
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.12 1
sudo update-alternatives --config python
Why Build Python from Source?
Building Python ensures compatibility with the Raspberry Pi’s ARM architecture, especially when precompiled binaries or repositories aren’t available.
With this guide, your Raspberry Pi is now equipped with the latest Python! 🚀