How to Install Python 3.10 on Ubuntu 22.04 LTS


Python is one of the most popular high-level languages, focusing on high-level and object-oriented applications from simple scrips to complex machine learning algorithms. Python is famous for its simple, easy-to-learn syntax, emphasizes readability, and reduces program maintenance costs and more straightforward conversion to newer releases. Python supports modules and packages, and one of the many is the popular PIP package manager.

Some of the features Python can do:

  • 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.

Release Highlights of Python 3.10:

New syntax features:

  • PEP 634, Structural Pattern Matching: Specification
  • PEP 635, Structural Pattern Matching: Motivation and Rationale
  • PEP 636, Structural Pattern Matching: Tutorial
  • bpo-12782, Parenthesized context managers are now officially allowed.

New features in the standard library:

  • PEP 618, Add Optional Length-Checking To zip.

Interpreter improvements:

Advertisement


  • PEP 626, Precise line numbers for debugging and other tools.

New typing features:

  • PEP 604, Allow writing union types as X | Y
  • PEP 613, Explicit Type Aliases
  • PEP 612, Parameter Specification Variables

Important deprecations, removals, or restrictions:

  • PEP 644, Require OpenSSL 1.1.1 or newer
  • PEP 632, Deprecate distutils module.
  • PEP 623, Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.
  • PEP 624, Remove Py_UNICODE encoder APIs
  • PEP 597, Add optional EncodingWarning

For the official Python 3.10 rundown notes, visit the official Python webpage What’s New in Python 3.10.

In the following tutorial, you will learn how to download the latest Python 3.10 and install the archive format or use a PPA with this version of Python on Ubuntu 22.04 LTS Jammy Jellyfish using the command terminal, along with how to download and compile as an alternative method.

Update Ubuntu

Before you begin, run a quick update to ensure your system is up-to-date to avoid conflicts during the tutorial and good system maintenance.

Advertisement


sudo apt update && sudo apt upgrade

Install Python 3.10 – PPA Method

The first and easiest solution for Ubuntu users would be to import the “deadsnakes” team Launchpad PPA. This will always contain the latest updates for Python and all extra packages that may be required.

See also  How to Install Plex Media Server on Ubuntu 22.10/22.04/20.04

First, install the prerequisite for adding custom PPAs.

sudo apt install software-properties-common -y

Second, add the deadsnakes/ppa to your APT package source list with the following command.

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

Once the repository has been imported, run an APT update to fresh your package manager to reflect the new imported PPA.

sudo apt update

You can now install Python 3.10 by executing the following code:

sudo apt install python3.10 -y

To verify the installation and Python 3.10 build version, perform the following.

Advertisement


python3.10 --version

Example output:

How to Install Python 3.10 on Ubuntu 22.04 LTS

Optionally, you can install the following extras.

Install development headers for building C extensions:

sudo apt install python3.10-dev -y

Install the standard library (venv) module:

sudo apt install python3.10-venv -y

Install the standard library (distutils) module:

sudo apt install python3.10-distutils -y

Install the (2to3.3.10) utility as well as the standard library (lib2to3) module:

Advertisement


sudo apt install python3.10-lib2to3 -y

Install the standard library (dbm.gnu) module:

sudo apt install python3.10-gdbm -y

Install the standard library (tkinter) module:

sudo apt install python3.10-tk -y

Alternative – Nightly Builds

For developers that require the latest nightly builds, the PPA has an additional branch for these builds. However, they should only be used by professionals and developers who need such builds.

Please note that developers or testers should only use this. The stable repository should suit nearly all users and is updated just as often as the nightly version. Also, this PPA can break, meaning you may need to revert to the stable repository.

sudo add-apt-repository ppa:deadsnakes/nightly -y

If you have the default 3.10 stable by (deadsnakes/ppa), you can run the apt update command to upgrade the existing packages.

sudo apt update

Then upgrade the packages:

Advertisement


sudo apt upgrade

If you do not have Python installed, use the installation command, and along with the same commands, add the extra packages such as dev, and venv packages, as shown in the stable branch tutorial rundown.

sudo apt install python3.10 -y

Suppose you want to roll back to the stable PPA. First, remove python 3.10.

sudo apt autoremove python3.10*

Next, remove the Nightly build PPA by adding the –remove to the original command as shown below.

sudo add-apt-repository --remove ppa:deadsnakes/nightly -y

Once done, update the APT repository list to reflect the removal.

sudo apt update

Now re-install Python 3.10; do not forget to re-add the stable repository. By default, you should have kept this.

See also  How to Install Akregator on Ubuntu 22.04 LTS

Install Python 3.10 – Manual Method

Download Python 3.10

First, visit the official download page and grab the latest version or the particular one you are after. The exact instructions should work on any version since you are compiling it. Once you have copied the link, use the wget command to download the Python 3.10 archive.

Advertisement


wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tar.xz

THIS WILL CHANGE VERY SHORTLY, MAKE SURE TO GET A FRESH LINK; THE ABOVE IS AN EXAMPLE COMMAND ONLY.

Extract the Python archive, and remember to change the version number if you downloaded a newer one.

tar -xf Python-3.10.{version}.tar.xz

Optionally, move Python 3.10 to a proper destination such as the /opt/ directory.

sudo mv Python3.10.{version} /opt/

Now install the dependencies required to install Python 3.10.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev pkg-config make -y

Navigate to the directory.

cd /opt/Python3.10.{version}/

Now, run the ./configure –enable-optimizations command.

Advertisement


./configure --enable-optimizations --enable-shared

Note, The script performs several checks to make sure all of the dependencies on your system are present. The ./configure –enable-optimizations will optimize the Python binary by running multiple tests, which will make the build process slower.

Now that you have built and configured the environment, it is time to compile it with the command make.

make

A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server.

For example, the LinuxCapable machine has 6 CPUs, and I can use all six or at least use 4 to 5 to increase speed.

make -j 6

Once you have finished building, install Python binaries as follows:

sudo make altinstall

Note, it is advised to use the make altinstall command NOT to overwrite the default Python 3 binary system.

Advertisement


Next, after the installation, you need to configure the dynamic linker run-time bindings with the ldconfig command.

sudo ldconfig /opt/Python3.10.{version}

Note, do not skip this, or you will face issues. You will also need to replace the path with your directory name and version.

See also  How to Install Python 3.8 on Linux Mint 21 LTS

Confirm that Python 3.10 is installed and the build version by running the following command:

python3.10 --version

Example output:

How to Install Python 3.10 on Ubuntu 22.04 LTS

Create a Virtual Environment

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 system to avoid clashing and disturbing your production environments.

To ensure Python 3.10 is installed correctly and functioning, create a quick Python project.

Advertisement


First, create the project directory and navigate to it:

mkdir ~/test_app && cd ~/test_app

Users that installed the PPA, you will need to install the Python 3.10 venv package if it has not already been installed.

sudo apt install python3.10-venv -y

Inside the project root directory, run the following command to create a virtual environment for the test name test_app.

python3.10 -m venv test_app_venv

Next, activate the virtual environment as follows.

source test_app_venv/bin/activate

After starting the virtual environment, you will now be in the shell prompt terminal. This will show the name of your environment that will be prefixed.

Example:

Advertisement


How to Install Python 3.10 on Ubuntu 22.04 LTS

To exit the virtual environment, use the following command:

deactivate

Install Python PIP with 3.10

By default, installing python-3.10 using the following APT command should work for all those using the Python PPA repository.

sudo apt install python3-pip

The manual installation method should have attached PIP; if not, it is advised to install PIP by downloading get-pip.py using the wget command.

wget https://bootstrap.pypa.io/get-pip.py

Next, install the file downloaded.

python3.10 get-pip.py

Once installed, it is a good idea to check for upgrades.

python3.10 -m pip install --upgrade pip

Example output:

Advertisement


How to Install Python 3.10 on Ubuntu 22.04 LTS

Now verify the PIP 3.10 version installed with the following command.

pip3.10 --version

Example output:

How to Install Python 3.10 on Ubuntu 22.04 LTS

Comments and Conclusion

In the tutorial, you have learned how to install Python 3.10 and create a virtual test environment on Ubuntu 22.04 LTS Jammy Jellyfish desktop or server.

At the moment of the tutorial, currently, Python 3.10 is the latest stable release, with Python still in beta mode. However, this will change soon enough and should be considered to be installed for future development work.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment