Install Python 3.11 on Ubuntu 20.04 - Step by step guide ?

Python is regarded as one of the most popular, multi-purpose, and beginner-friendly programming languages. It’s used in a wide selection of areas including data science, machine learning, rapid prototyping, and creating web applications.

Python 3.11 was released a few months ago this year, October 2022 and provides a wide array of improvements such as faster speed of execution, better error diagnostics, and improved modules to mention just a few.

Here at LinuxAPT, we shall look into how to install Python 3.11 on Ubuntu 20.04.


Main features Python includes:

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping or production-ready software development.


Steps to install Python 3.11 on Ubuntu 20.04

1. Perform System Update

To begin, you need to install dependencies that will be required during the installation of Python 3.11. But first, refresh the Ubuntu package lists:

$ sudo apt update

Next, install the software-properties-common package. This provides an abstraction of APT repositories and provides some useful scripts that help you manage software applications from third-party vendors such as PPAs:

$ sudo apt install software-properties-common


2. Install Python3.11 on Ubuntu

To successfully install Ubuntu, we need to add the deadsnakes PPA which provides the most recent versions of Python such as Python 3.7 and 3.8 for Ubuntu 18.04 and Python 3.9 to Python 3.11 For both Ubuntu 18.04 and Ubuntu 20.04.

So, proceed with the addition of the deadsnakes PPA:

$ sudo add-apt-repository ppa:deadsnakes/ppa

To continue adding the PPA, proceed and hit ENTER.

Next, update the package lists to sync your system with the newly added deadsnakes PPA:

$ sudo apt update

Finally, use the APT command to install Python 3.11:

$ sudo apt install python3.11

To confirm that Python3.11 is installed, run the command:

$ python3.11 —-version


3. Install additional Python packages

Additionally, there are some useful packages that supplement the default Python installation that you might consider installing.

Consider installing development headers for building and compiling C extensions:

$ sudo apt install python3.11-dev

Also, consider installing the standard library `dbm.gnu` module:

$ sudo apt install python3.11-gdbm

Finally, install the Python venv module that allows you to create virtual environments:

$ sudo apt install python3.11-venv

You can also consider installing the Tkinter Python Library:

$ sudo apt install python3.11-tk


How to access the Python 3.11 shell ?

To access the Python shell run the command:

$ python3.11

Now, you can run your Python code.

Python's venv module is a virtual environment is a Python environment such that the Python interpreter, libraries, and scripts installed into it are isolated from those established in other virtual environments, and (by default) any libraries installed on your operating system, for example, those that are installed on your Ubuntu operating system to avoid clashing and disturbing your production environments.

To make sure Python 3.11 is installed correctly and functioning, create a quick Python project as follows.

First, create the project directory and navigate to it:

$ mkdir ~/test_app && cd ~/test_app

Now inside the project root directory, run the following command to create a virtual environment, for the test name it test_app:

$ python3.11 -m venv test_app_venv

Note, the compiled installation included venv. However, if you installed using the APT package manager method, you may need to install the venv package if you encounter problems:

$ sudo apt install python3.11-venv -y

Next, activate the virtual environment:

$ source test_app_venv/bin/activate

After starting the virtual environment, you will now be in the shell prompt terminal. You will notice the name of your environment will be prefixed.

By default, PIP3.11 should be installed, which is the most used package manager for Python.

Before you begin, check if any upgrades are available for PIP:

$ python3.11 -m pip install --upgrade pip

In the tutorial to test the installation, Apache-Airflow was installed.

Example:

$ pip3.11 install apache-airflow

If using the APT package manager method, you will need to install the Python 3.11-dev version. Failure to do this will result in most PIP packages not installing correctly.

Manual installations (compiled) do not need to do this as it comes natively installed:

$ sudo apt install python3.11-dev -y

Remove the test application using PIP3.11:

$ pip3.11 uninstall apache-airflow

To exit the virtual environment, use the following command:

$ deactivate


[Need help in fixing Python issues ? We can help you. ]

This article covers how to install Python 3.11 on Ubuntu 20.04 LTS Focal Fossa using the PPA by Snakeyes or compiling from source and learning how to create a quick virtual environment.

Related Posts