In the next article we will take a look at how can we install python 3.9 on Ubuntu 20.04. In case there is still someone who does not know, Python is one of the most popular programming languages in the world. It is versatile and is used to create all kinds of applications, from simple scripts to complex algorithms. Being easy to understand, easy to learn, and with simple syntax, Python is a popular choice for both beginners and experienced developers.
Python 3.9 is the last major version available of this language. It includes many new features like; new dictation operators, string methods for removing prefixes and suffixes, new str functions, IANA time zone support, and more. All the news can be consulted in the news note on this version Python.
Python 3.9 installation
In the following lines, we will see two ways to install Python 3.9 on Ubuntu 20.04. The first option will be installing the package from the deadsnakes PPA, and the second will be to build Python 3.9 from the source code that we can download from the Python website.
The installation of Python 3.9 in Ubuntu with apt is a simple process, which can also be carried out very quickly. To start we open a terminal (Ctrl + Alt + T) and we will update the list of packages available from the repositories:
sudo apt update
Now we are going to install the necessary prerequisites, if we don’t have them installed yet:
sudo apt install software-properties-common
The next thing we will do is add the deadsnakes PPA to the list of sources in our system:
sudo add-apt-repository ppa:deadsnakes/ppa
After adding the repository, in Ubuntu 20.04 the list of available packages will be updated. Once the repository is enabled and everything updated, we can proceed to install python 3.9 running in the same terminal:
sudo apt install python3.9
After the installation, we will verify that the installation was correct typing in terminal:
If on the screen we see a message like the one shown in the previous screenshot, Python 3.9 will be installed in our Ubuntu and we can start using it.
From the source
Compiling Python from source will allow us to install the latest version of Python and customize the compilation options. But nevertheless, it will not allow us to maintain the Python installation through the apt package manager. In the following lines we are going to see how to compile Python 3.9 from source.
To start we will install the necessary dependencies. In a terminal (Ctrl + Alt + T) we will have to write:
sudo apt update; 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 let’s download the source code of the latest version from the download page Python with wget. In a terminal (Ctrl + Alt + T) we can use the command:
Once the download is complete, we will have to extract the compressed file with gzip. We will achieve this by writing:
tar -xf Python-3.9.0.tgz
We continue to switch to the Python directory that was just created. Once inside, we will run setup script. It will perform a series of checks to make sure that all the dependencies are present in our system:
cd Python-3.9.0 ./configure --enable-optimizations
When the previous command finishes, we will start the Python 3.9 build process:
make -j 12
When the build process is complete, we can install python typing in the same terminal:
sudo make altinstall
Make install can overwrite or mask the python3 binary. In the python page recommend make altinstall instead of make install, since it only installs exec_prefix / bin / pythonversion.
Upon completion, Python 3.9 will be installed and ready to use. For check for successful installation, we can write in the terminal:
In these lines we have seen how Ubuntu 20.04 users can install this version of Python in a simple way. Now anyone can start developing their projects with Python 3.9. If you need help to start developing with Python, this language offers its documentation on the project website.