How to Install Python 3.9 on Debian 11

Whether you are a beginner or an expert programmer, you must have heard about Python. Python is one of the most popular and powerful programming languages. It is an open source, free language for beginners and even for commercial use.

The versatility of this language is superb as it is used by developers to build all types of applications. From machine learning algorithms to web apps, everything is here in this programming language.

Python has recently launched it’s new version which is the 3.9 version. It included many new features in this new version. The new features include new str functions, dict operators as well as IANA time zone support and much more.

Let’s explore the idea of installing Python 3.9 in our Debian 11 OS.

Installing Python 3.9 in Debian 11  

The first step in installing Python 3.9 in our Debian 11 is to update the apt cache index. For this purpose type the following command:

$ sudo apt update

If there are some packages that need to be upgraded then type the following command:

$ sudo apt upgrade

However, in my case it wasn’t necessary as you can see all the packages are up to date.

Now that we have successfully upgraded our system, let’s restart it with the following command:

$ sudo reboot

Now comes the part where we start working on the installation of Python 3.9. For this purpose, we have to install the dependency packages. Use the following command:

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

Next step is to visit the Python official page and extract from there the version 3.9. You will find it on the following link:

https://www.python.org/downloads/

After this type the following command by editing the version in the command:

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

After this we have to extract the file that was downloaded. We can extract it with the following command:

$ tar xvf Python-3.9.6.tgz

After successfully extracting the downloaded file, let’s change to the working directory. This is to create a python folder. First we change the directory with the following command:

After this, we will run the configuration command. For this purpose type the following command in your terminal:

$ ./configure --enable-optimizations

The next step is now to start the python build process. For this purpose type the following command in your Terminal:

$ sudo make altinstall

If you have successfully installed Python then your output will look like this after the above command:

You will get the following message at the end of the output of the above command:

To verify the installation type the following command:

$  python3.9 --version

We can also install the Python modules from the following link:

https://pypi.org/

Click on the link above and whichever module you want to install, insert in the following command:

$ python3.9 -m pip install <moduleName>

Now that everything is complete, let’s just start using Python 3.9. For using the python 3.9 shell type the following command:

$ python3.9

Isn’t it amazing? Let’s write our very first program in Python 3.9 in Debian 11. We all know what programmers first program was; printing hello world. Let’s just print hello world.  Type the following:

>>> print("Hello World!")

To close or exit the python shell session then type the following command:

>>> exit()

Conclusion

Python is one of the most famous languages in Computer Science. Every developer at some point was exposed to this language. And rightly so! As it offers a huge range of areas. We can develop Web apps as well as Machine learning algorithms in this language.

We have shown you each and every little step along the way to install Python 3.9 on Debian 11 along with examples. To help you get started we even demonstrated a simple program of printing hello world in Python 3.9 shell. All this with the help of screenshots will be enough to install Python 3.9 on Debian 11.

Subscribe to Our Newsletter
Join our Newsletter and get the latest Linux news and tips
in your inbox for FREE.