Planning to get Python 3.11 installed for your project work? Here’s how to install Python 3.11 in Ubuntu and related distros.
Python 3.11 was released on Oct 25, 2022, and claims to be 10-60% faster than the prior Python 3.10 version.
As always, the feature and improvement list are significantly high in 3.11. Here’s a brief.
- Error tracebacks are not more definite, which gives you an exact statement that causes the error.
- Introduction of exception groups and new except* syntax
- You can add custom text in the base expression for better error handling in your code.
- Introduction of Variadic generic to allow array-like structure in numerical Python libraries )such as NumPy)
- Dictionary type TypedDict gets improvement where you can now specify whether individual dictionary items are mandatory or optional.
- Introduction of Self annotation, which allows classes to return their own type instance.
And many more, which you can read in detail on the official 3.11 highlights page.
Table of Contents
Current Python versions in Linux Distros
Ubuntu 22.04 LTS have Python 3.10, whereas the recently released Ubuntu 22.10 Kinetic Kudu also have the same. However, Kinetick Kudu will probably feature 3.11 within a few weeks. The following PPA does not have a release file for Kinetic Kudu. Hence will not work on Ubuntu 22.10. However, Ubuntu 22.10 Kinetic Kudu already have the Python 3.10.7 and soon will be updated with 3.11 via Ubuntu’s usual updates.
Also, Fedora 37 (released on Nov 15) already has Python 3.11.
So, if you are running Ubuntu 22.04 LTS, Linux Mint 21 or any Ubuntu-LTS-based distros, here’s how you can install Python 3.11 via a PPA.
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. Many default applications and packages depend on the 3.10 version.
How to install Python 3.11 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.11 using the below command.
sudo apt install python3.11
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.11 as default requires some additional steps. Follow along.
However, before you do that, make sure you know which applications depend on Python 3.10. You can easily find it out using
apt-cache rdepends command as below.
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.11 as the default Python3
- First, check the current default 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.11 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 commands and change the versions at any time.
If you switch to 3.11 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.