How to Install Python 3.9 on Debian 11
Python is a free, open-source programming language that was originally published in 1991 and has since gained widespread adoption. It's used for general purpose programming which makes it perfect to create apps on your phone or computer.
It is the newest of the three most popular coding languages (C++ and Java being the other two). Python runs on Windows, Linux/Unix, Mac OS X and has been ported to the Java and .NET virtual machines.
Python comes with clear syntax and predictable semantics, and a large standard library. Python is a versatile language that can be used for many kinds of programming: desktop applications, web applications, network programming, GUI development, etc.
In this article, we'll show how to install Python 3.9 programming language on a Debian 11 system as a Linux user.
In order to be able to install Python 3.9 on Debian 11, your server must meet the following prerequisites:
- Access to root or sudo user.
- A fresh Debian 11 server was installed and updated to the latest packages.
Updating the System
Update your APT cache index and upgrade installed packages with the following command.
sudo apt update
sudo apt -y dist-upgrade
Python needs some dependencies for its core features and packages, so let's install them with the following command.
sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
Installing Python 3.9 on Debian 11
In this step, we will use Python's source code to install the latest available version of Python.
Use the wget program to download the latest version of Python from its official page.
As of writing, Python 3.9.7 is the latest version. You can navigate to its official page to check if there is a new version and update this guide with the new link to download it.
Once the download is finished, it's time to extract the contents of the compressed file and move into the extracted directory.
tar xzf Python-3.9.7.tgz
Once inside the new directory, run the following command to configure the build.
The altinstall method is recommended, instead of the regular make install, because it overwrites only the Python binaries. This method keeps your current installation intact.
A successful installation of Python will be marked by a congratulations message and the build finished successfully.
If you didn't get a successful installation, please read the error logs and fix the issue with your system.
You can check if your system installed Python 3.9 correctly by running the following commands:
If you don't get any errors while installing Python 3.9, the command should work without any problem and print the latest Python version installed on your system.
To install Python modules, you need to run the following command inside your Python 3.9 directory.
python3.9 -m pip install <module>
Where: <module> is the name of a module to be installed, for example sphinx, PyMySQL etc. You can get a list of all Python modules available for installation on its official website.
For example, let's install the sphinx module:
python3.9 -m pip install sphinx
Testing the Python Installation
Now that Python 3.9 is installed, let's run a simple hello world with the Python Interpreter and see that it works.
You can launch the Python Interpreter from the bin directory of your Python installation with the following command.
This will launch the Python interpreter and you'll see a >>> prompt to enter Python commands.
In the interpreter, you can enter your Python code and see the result of its execution in real-time. Let's run a simple hello world example. Enter the following print statement in the interpreter.
print("Howtofore, Hello World")
Once you enter the command and hit Enter, you'll see that it prints the Howtofore, Hello World message on your terminal.
To exit the Python Interpreter, you can enter the following command.
Congratulations! You have successfully installed Python 3.9 on your Debian 11. You can now start writing Python code and executing it with the interpreter.
In this blog post, we have shown you how to install Python 3.9 engine on Debian 11, and how it can be useful in your project development. We hope that this article has been helpful for you. If you want more information about Python 3.9, please visit its official site.