Python 3.12 was released on October 2, 2023 with a bunch of new features and performance improvements. In addition, this release also brings much-needed cleaning up of deprecated APIs and performance updates to various modules.
The entire Python 3.12 feature list is huge; here’s a quick recap of the new features:
- New type Parameter Syntax
- Syntactic formalization of f-strings
- A Per-Interpreter GIL
- Low-impact monitoring for CPython
- Making the buffer protocol accessible in Python
- Improved Error Messages
- slice objects are now hashable
You can read in detail about these on the official release page.
Table of Contents
Python versions in Linux distributions
As of publishing this, all the Linux distributions are currently providing Python 3.11, which was the last stable release. For example, the Ubuntu 23.04 and Fedora 38 have version 3.11. However, there is a likely chance that Fedora 39, Ubuntu 23.10 may get this version at a later date, after the official release.
In addition, the Ubuntu 22.04 LTS is officially at Python 3.10 due to its nature. You can use the steps below to install this latest version in all the distribution versions.
Note: Use this method with caution. Make sure you know what you are doing because replacing the base Python version of a Linux distribution may cause an unstable system – such as the Terminal not opening, applications crashing, etc. Because those applications and packages depend on the 3.11 version.
How to install Python 3.12 in Ubuntu and related distros
- Open a terminal prompt and add the following PPA.
sudo add-apt-repository ppa:deadsnakes/ppa
- Refresh the cache using the below command.
sudo apt update
- And install Python 3.12 using the below command.
sudo apt install python3.12
Install in Fedora, CentOS, Arch Linux
For Arch Linux, you can easily install it when it is available in core repo. Once available, you can simply update your Arch system to get this version. Keep a watch in this page. If you don’t want to wait, get it from the AUR (testing).
For Fedora, CentOS, you need to download the official version from this page and compile it. Alternatively, you need to wait a few weeks until it is officially available via normal Fedora distribution channels.
Set Default Python Versions
In theory, you can install multiple versions of Python in Linux distros, but the default can only be one version. Setting up Python 3.12 as default requires some additional steps.
However, before you do that, make sure you know which applications depend on Python 3.11 or 3.10 (for Ubuntu LTS version). You can easily find it out using
apt-cache rdepends command as below.
apt-cache rdepends python3.11
apt-cache rdepends python3.10
debugpoint@debugpoint-22-04:~$ apt-cache rdepends python3.10 python3.10 Reverse Depends: python3.10-dbg python3.10-venv python3.10-full libpython3.10-testsuite idle-python3.10 idle-python3.10 python3.10-minimal python3.10-doc python3.10-dev python3 virtualbox python3.10-venv python3.10-full libpython3.10-testsuite kitty idle-python3.10 idle-python3.10 python3.10-minimal python3.10-doc python3.10-dev python3.10-dbg python3-uno python3-all python3.10-dbg virtualbox stimfit python3.10-venv python3.10-full python3-stfio python3-escript-mpi python3-escript python3-csound plasma-firewall pitivi obs-studio liferea libpython3.10-testsuite libglib2.0-tests kitty idle-python3.10 idle-python3.10 cluster-glue atac rhythmbox-plugins python3.10-minimal python3.10-doc python3.10-dev python3 python3-uno python3-all gedit
Use Python 3.12 as the default Python3
- First, check the current default Python version using the below command from the terminal.
update-alternativesto create symbolic links to
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2
- And choose which one to use as Python3 via the command:
sudo update-alternatives --config python3
Now, you can start using the latest Python in your current Ubuntu version for your work/study. You switch to the stock version using the above
update-alternatives --config python3 command and change the versions at any time.
Compiling Python 3.12 source
You can also compile Python from source using the below set of instructions. However, it is not recommended unless you really need to compile.
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
tar -xf Python-3.12.0.tgz
cd Python-3.12.*/ # ./configure --enable-optimizations
make -j 16 (assuming 16 cores in your system. Change the value using the output of nproc)
Verify using the below command after compilations:
python3.12 --version Python 3.12.0
Installing PIP and modules
While using Python, you need pip to install Python modules. However, it is not installed by default in Ubuntu. You can install it using the following command from the terminal:
sudo apt install python3-pip
For other distributions, you can visit this page for more instructions regarding pip.
If you switch to 3.12 using the above install method, then make sure you check all the necessary apps to see whether they are working fine.
Finally, do let me know in the comment box if you run into problems.