Python 3.11 Released! How to Install in Ubuntu 22.04 | 20.04 | 22.10

The popular Python programming language released version 3.11 today. Here’s the new features and how to install guide for all current Ubuntu releases.

Python 3.11 claimed to be 10-60% faster than the previous 3.10, and features:

  • Exception Groups and except* to raise and handle multiple unrelated exceptions simultaneously.
  • Add add_note() method to BaseException to enrich exceptions.
  • Add the tomllib module to the standard library for parsing TOML
  • Point to exact expression that caused error when printing tracebacks.
  • New -P command line option and PYTHONSAFEPATH environment variable
  • Add TypeVarTuple, enabling parameterisation with an arbitrary number of types
  • Required[] and NotRequired[] to mark whether individual TypedDict items must be present.
  • Add Self to annotate methods that return an instance of their class
  • LiteralString to accept arbitrary literal string types, such as Literal["foo"] or Literal["bar"].
  • dataclass_transform to decorate a class, metaclass, or a function that is itself a decorator.
  • Removed Py_UNICODE encoder APIs
  • Macros converted to static inline functions
  • Many legacy standard library modules deprecated and to be removed in Python 3.13

How to Install Python 3.11 in Ubuntu

For Ubuntu 22.04, Ubuntu 20.04, Ubuntu 18.04, and their derivatives, such as Linux Mint, there’s a popular Deadsnakes PPA maintains the packages for Python 3.11 as well as other Python versions.

NOTE: The PPA does not support Ubuntu 22.10. You may follow the bottom link to build it from source tarball.

1. First, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to add the PPA:

sudo add-apt-repository ppa:deadsnakes/ppa

Type user password when it asks (no asterisk feedback) and hit Enter to continue

2. Then refresh package cache via command below, though it’s done automatically in Ubuntu 20.04+:

sudo apt update

3. Finally, install python 3.11 via command:

sudo apt install python3.11

Or replace python3.11 with python3.11-full for IDE, pip package manager, etc.

Verify:

To verify, run python3.11 --version, python3.11 -m pip --version in terminal.

Set Python 3.11 as default

NOTE: change default Python3 in Ubuntu may cause issues for some default apps, such as GNOME Terminal

You may set the new Python package as default by using update-alternatives command line tool.

1. First, run command to create symbolic links for system default python (change python3.10 depends your Ubuntu edition)

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 110

2. Then, add the new Python 3.11 via command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 100

3. After that, you may choose which Python as Python3 at any time by running command:

sudo update-alternatives --config python3

Compile and install Python 3.11 manually from source

User may also compile the programming language from source tarball manually.

First, download the source from Python web site, then you may follow this step by step guide that I’ve tested in my Ubuntu 22.10 machine.

Original Article