Python is basically one of the most popular and versatile programming languages. It's a multi-purpose language and provides a myriad of use cases such as the development of full stack web apps, artificial intelligence, web scraping, and visualization of data in cool dashboards in data science.
Currently, Python 3.9.7 is the latest version of Python and provides quite a number of benefits including flexible variable and function notations, union operators in dict, support for IANA timezone and so many others.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Python queries.
In this context, we shall look into the installation procedure of Python 3.9 on Debian 11.
1. Install Python3 dependencies
Here, we will compile Python from source. This allows us to install the latest version of Python and further customize build options.
To get started, update the package index:
$ sudo apt update
Next, install the dependencies and libraries required to build Python:
$ sudo apt install build-essential libncurses5-dev zlib1g-dev libnss3-dev libgdbm-dev libssl-dev libsqlite3-dev libffi-dev libreadline-dev curl libbz2-dev
This installs a host of additional packages and other dependencies.
2. Download and install the latest Python 3.9
Next, we will download the gzipped source code file from the Official Python release and download page as shown.
So, to download the tarball file, run the below command:
$ sudo wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
Next, extract the compressed file as follows:
$ tar -xvf Python-3.9.1.tgz
After the extraction, you will now have 2 files: the tarball file and the decompressed folder ( Python-3.9.7).
To compile Python from source navigate to the uncompressed folder:
$ cd Python-3.9.1
Then run the configure script with the below command:
$ /configure --enable-optimizations
This runs multiple tests and takes quite some time. In our case, this took approximately 20 minutes.
Then commence the build process:
$ make -j 2
The -j option specifies the number of CPU cores. You can check out the number of cores on your Linux system by executing the nproc command:
$ nproc
Finally, run the following command to install Python binaries:
$ sudo make altinstall
This finalizes the installation of Python 3.9.7 on your system.
3. Test Python installation
You can confirm the version of Python installed using the command:
$ python3.9 --version
You can access Python 3.9 shell using the command:
$ python3.9
To give it a test run, we will write a simple program to find the sum of two variables, x and y:
x = 35
y = 75
z = x + y
print("Hello, the sum of x and y is", +z)
The Output will look like this:
Hello, the sum of x and y is 110
This article covers on how to install Python 3.9.7 on Debian 11. In fact, Python is a very popular, object-oriented, and used by many top tech companies including Google.