How To Set up Python 3.10 on Ubuntu 20.04

In this article, we want to teach you How To Set up Python 3.10 on Ubuntu 20.04.

Python is a popular programming language. It works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). Also, it has a syntax that allows developers to write programs with fewer lines than some other programming languages. It can be treated in a procedural way, an object-oriented way, or a functional way.

It is used for:

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

How To Set up Python 3.10 on Ubuntu 20.04

Before you start to set up Python 3.10, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Ubuntu 20.04.

Now follow the steps below to install Python 3.10.4 Latest version on Ubuntu 20.04.

Install Python 3.10 on Ubuntu 20.04 from APT Repository

The first way to install Python 3.10 on Ubuntu 20.04 is to use the APT repository. First, update your local package index with the following command:

sudo apt update

Then, you need to install the dependencies for adding the PPA repository:

sudo apt install software-properties-common -y

Next, use the following command to add the PPA deadsnake to the APT repository:

sudo add-apt-repository ppa:deadsnakes/ppa

At this point, you can install Python 3.10 on Ubuntu 20.04 with the following command:

sudo apt install python3.10

You can verify your Python 3.10 installation by checking its version:

python3.10 --version
Output
3.10.4

Install Python 3.10 on Ubuntu 20.04 from the Source

Another way to install Python 3.10 on your server, is to build from the source code. It’s recommended to use this way than the APT repository.

First, update your local package index with the following command:

sudo apt update

Then, install the dependencies with the command below:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

Now you need to visit the Python Downloads page and copy the link address of the Python 3.10.04 gzipped source tarball. Use the wget command to download it:

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

When your download is completed, extract your downloaded file with the following command:

tar -xf Python-3.10.*.tgz

Switch to your extracted directory:

cd Python-3.10.*/

Next, run the configure script to check the required dependencies:

./configure --enable-optimizations

At this point, you can start your build process with the make command. But before this, you need to check the number of your cores with the command below:

nproc

Example output:

Output
2

Then, build your process with the command below:

make -j 2

Note: The (-j) corresponds to the number of cores in your system to speed up the build time.

When your build process is completed, use the following command to install Python 3.10 on Ubuntu 20.04:

sudo make altinstall

Verify your Python 3.10 installation by checking its version:

python3.10 --version
Output
Python 3.10.4

How To Use Python 3.10

At this point, we want to create a test virtual environment to see that Python 3.10 is working correctly on Ubuntu 20.04.

First, create a project directory and switch to it with the command below:

mkdir ~/test_app && cd ~/test_app

Then, create a virtual environment with the following command, for the test name it test_app:

python3.10 -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.10-dev python3.10-venv -y

Next, activate your 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.10 should be installed, which is the most used package manager for Python.

Check for the PIP upgrades:

python3.10 -m pip install --upgrade pip

For example, you can install Apache-Airflow with the command below:

pip3.10 install apache-airflow

To remove the application you can use the following command:

pip3.10 uninstall apache-airflow

To exit the virtual environment, use the following command:

deactivate

Conclusion

At this point, you learn to Set up Python 3.10 on Ubuntu 20.04.

Hope you enjoy it.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular