Python is one of the most popular programming languages in the world, if not the most popular one. It is a general-purpose programming language that is mostly used for back-end web development, data science, machine learning and software development.
Python 3.11 is the newest pre-release version of Python.
In this tutorial we’ll install Python 3.11 on an Ubuntu 22.04 machine.
Table of Contents
Major changes to Python 3.11
Python3.11 is bringing significant changes; these are some of them:
- It is 10-60% faster than Python 3.10, the most recent stable release of python.
- Spots error trace-backs better than its predecessors; not only it tells you in which line the error happened, but also the exact segment of the statement in which python encountered the obstacle.
- Unpacking iterables with asterisk without the need of parentheses in for statements.
Also, there are minor changes to the language.
How to install Python 3.11 on Ubuntu
Since python3.11 is still a testing release; there is no official package already present on apt package sources, so we have to add a PPA (Personal Package Archive), then we can install python3.11 using apt package manager.
There are dependencies for adding a custom PPA. You can install them using the following command:
sudo apt install -y software-properties-common
Now you can add one of the next deadsnakes PPAs.
a) The normal one, this will let you install more stable versions of python (3.11 or 3.10), it will ask you to hit enter:
sudo add-apt-repository ppa:deadsnakes/ppa
b) The nightly PPA, which has the newest test pre-releases:
sudo add-apt-repository ppa:deadsnakes/nightly
Update apt package list by executing the next command:
sudo apt update
Now you can run the next command to install Python 3.11.
sudo apt install -y python3.11
Some additional packages (Optional)
Now you have Python 3.11 installed and running in your Ubuntu, but there are additional packages that you can install now, besides your often used libraries. These will greatly benefit you if you are serious about programming in python.
python-dev is a package that contains Python C headers, that significantly boasts performance for libraries that use Python C headers:
sudo apt install -y python3.11-dev
python-tk is python’s de facto of GUI, which can come in handy if you are building a graphical user interface application:
sudo apt install -y python3.11-tk
python-gdbm is a gnu reinterpretation of dbm, a powerful objects-storing database interface for DBM-style databases:
sudo apt install -y python3.11-gdbm
venv (the standard library virtual environment), this library lets you set-up a virtual environment of python, within which you can install packages and configure various things without affecting your system settings.
sudo apt install -y python3.11-venv
Configuring a Default Python Version in Ubuntu
Ideally, you have multiple versions of Python 3 by now, but what if you want to use one version as your default over the other? Follow the next steps to achieve that!
Order all python3 versions with numbers as possible alternatives of Python 3:
sudo update-alternatives --install /usr/bin/python3 /usr/bin/python3.11 1
sudo update-alternatives --install /usr/bin/python3 /usr/bin/python3.10 2
Now update the defaults (you can always change this whenever you need):
sudo update-alternatives --config python3
This article demonstrated how to install Python 3.11, also it showed what Python 3.11 offers you as a programmer, various libraries to enhance your coding experience, and lastly, how to change the default Python 3.
I think you’re missing the <name> part of that command. It seems that if you add “python3” after /usr/bin/python3 it proceeds.