Linux Mint

How to Install Python 3.9 on Linux Mint 20?

Python is popular and is almost used in every type of computer science project. However, it has gained a lot of popularity in Artificial intelligence and its associated fields like Machine Learning, Deep Learning, etc.

Python 3.9 is the latest major release of Python. It is leveraged with many updates.

Python 3.9 is available from the deadsnakes PPA repository. Moreover, we can also build Python on Linux Mint 20 from the source code.

Installing Python 3.9 on Linux Mint 20 from the PPA repository

Installing Python 3.9 on Linux Mint 20 from the deadsnakes PPA repository is very easy and straightforward.

Perform the below-given steps to install Python 3.9 on Linux Mint 20 from the deadsnakes repository:

Step 1: Update apt cache
Fire up the terminal and update the apt cache with the command:

$ sudo apt update

Step 2: Install the dependencies
Next, type the command to install the required dependencies that are a prerequisite of Python 3.9:

$ sudo apt install software-properties-common

Step 3: Add PPA repository
Next, add the PPA repository:

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

Step 4: Install Python 3.9
Install Python 3.9 as follows:

$ sudo apt install python3.9

Press ‘y’ to continue installing Python 3.9.

Step 5: Verify the Python 3.9 installation
After installing Python 3.9, verify the installation with the command:

$ python3.9 --version

Python 3.9 is successfully installed on Linux Mint 20.

Note: In case if you face any dependency issue after installing Python 3.9, then run the below-given command to fix the issue:

$ sudo apt-get -f install

Installing Python 3.9 on Linux Mint 20 from the source code

This is another way of installing Python 3.9 Linux Mint 20. It is not recommended to install Python 3.9 from the source code. However, you may need it in various situations.

Perform the below-given steps to install Python 3.9:

Step 1: Install required dependencies for Python 3.9
First, update the apt repository and install dependencies:

$ sudo apt update

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

Step 2: Get the Python 3.9 source code
Next, get the latest Python 3.9 source code with the wget command:

$ wget <a href="https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz">https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz</a>

Step 3: Extract Python 3.9 source code tar file
When the Python 3.9 source code tar file is downloaded, extract the archive with the command:

$ tar -xf Python-3.9.1.tgz

Step 4: Run configure script
Next, navigate to the Python 3.9.1 directory and run the configure script:

$ cd Python-3.9.1

$ ./configure --enable-optimizations

The –enable-optimizations run the various tests and improves the configuration process.

Step 5: Build Python 3.9
Once Python 3.9 is configured, the next step is to build it with the command:

$ make -j

To make the build process faster, you can also specify the number of cores with the –j option as follows:

$ make -j 8

Step 6: Install Python libraries
Next, install Python 3.9 with the command:

$ sudo make altinstall

The altinstall will overwrite the existing Python3 binary.

Python 3.9 is installed successfully.

Conclusion

Python 3.9 is the newest release of Python. It is available from the deadsnakes repository and source code. This post explains the Python 3.9 installation on Linux Mint 20.

About the author

Kamran Sattar Awaisi

I am a software engineer and a research scholar. I like to write article and make tutorial on various IT topics including Python, Cloud Computing, Fog Computing and Deep Learning. I love to use Linux based operating systems.