- Do not remove your system
python3(often 3.11 or 3.13); keep it for the OS packages. - Using a virtual environment is the safest way to avoid conflicts between system and project packages.
- If you use
update‑alternatives, make sure yourspotduser (orpi/root) uses the same Python version in its shell.
Open a terminal and run:
python3 --version
python --versionIf you see Python 3.13 or higher, continue with the steps below.
This is the easiest method if you are on Raspberry Pi OS or Ubuntu/Debian.
- Update package list:
sudo apt update- Install Python 3.12 and
pip:
sudo apt install python3.12 python3.12-venv python3.12-dev- Verify the installation:
python3.12 --versionYou should see something like:
Python 3.12.x- Install
pipfor Python 3.12 (if not already present):
python3.12 -m ensurepip --upgrade- Test with
pip:
python3.12 -m pip --versionIf you want python and python3 to point to Python 3.12 in your shell, you can use update‑alternatives.
- Add Python 3.12 to
update‑alternatives:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1- Choose the default Python 3:
sudo update-alternatives --config python3Select the entry for python3.12.
- Verify:
python3 --versionIt should now show Python 3.12.x.