Sep 29, 2023 4 min read

How to Install Python 3.9 on Debian 12

Install Python 3.9 on Debian 12 with our step-by-step tutorial. Python is a simple, beginner-friendly, extensive library ecosystem.

Install Python 3.9 on Debian 12
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Python 3.9 on Debian 12, let's briefly understand – What is Python?

Python is known for its simplicity and readability. It is beginner-friendly, making it an ideal choice for programmers. With its extensive library ecosystem and cross-platform compatibility, Python enables developers to build a wide range of applications, from web development to data analysis and machine learning.

Python 3.9 on Debian 12 is the latest version of the popular programming language and the Debian operating system. With a host of new features and improvements, Python 3.9 brings enhanced performance and security.

In this tutorial, you will install Python 3.9 on Debian 12. We will also address a few FAQs on how to install Python 3.9 on Debian 12.

Advantages of Python

  1. Simplified Syntax: Python has a clean and readable syntax, making it easy to learn and write code efficiently.
  2. Versatility: Python is a versatile language used in various domains, including web development, data analysis, and artificial intelligence.
  3. Extensive Library Support: Python offers a vast collection of libraries and modules, providing ready-to-use solutions for different tasks.
  4. Platform Independence: Python programs can run on different platforms without the need for major modifications.
  5. Strong Community Support: Python has a large and active community, offering abundant resources, documentation, and active forums for assistance.

Installing Python 3.9 in Debian 12

Updating the apt cache index is the first step in installing Python 3.9 in our Debian 12 system. To accomplish this, issue the below given command:

sudo apt update

Type the following command if there are any packages that need to be upgraded:

sudo apt upgrade

However, as you can see, all the packages in my instance are up to current, so it wasn't necessary.

We've upgraded our system successfully; let's restart it with the following command:

sudo reboot

The process of installing Python 3.9 will now be initiated. We need to install the dependent packages in order to achieve this. Use the command as follows:

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

The following step is to go to the official Python website and download version 3.9 from there. It can be found through the subsequent link:

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

After that, enter the following command while changing the version:

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

After that, we have to extract the downloaded file. It can be extracted using the command below:

tar xvf Python-3.9.6.tgz

Let's switch to the working directory after the downloaded file has been successfully extracted. It's for making a Python folder. First, we use the command below to change the directory:

cd Python-3.9.6

We shall then execute the configuration command. In order to accomplish this, enter the following command into your terminal:

./configure --enable-optimizations

The Python build procedure will now be started as the following step. In order to accomplish this, enter the following command into your Terminal:

sudo make altinstall

After running the above-mentioned command, your output should appear as follows if Python was successfully installed:

At the end of the output from that previous command, you will see the following message:

Type the next command to check the installation:

python3.9 --version

The following link allows us to install the Python modules as well:

https://pypi.org/

Click the aforementioned link, then use the following command to install any desired modules:

python3.9 -m pip install <moduleName>

Since everything is finished now, let's just use Python 3.9. The following command should be used to use the Python 3.9 shell:

python3.9

We will now create our first Python 3.9 program in Debian 12. Everyone is aware of the first program a programmer ever wrote, which printed "Hello World." Just print "hello world" for now.  Fill in the following:

>>> print("Hello World!")

Type the following command to end or quit the Python shell session:

>>> exit()

FAQs to Install Python 3.9 on Debian 12

What are the prerequisites for installing Python 3.9 on Debian 12? 

Before installing Python 3.9 on Debian 12, ensure that you have administrative privileges and an active internet connection.

How can I install Python 3.9 on Debian 12 using the package manager? 

You can install Python 3.9 on Debian 12 by running the command: sudo apt install python3.9.

Can I install Python 3.9 alongside other Python versions on Debian 12? 

Yes, it is possible to have multiple Python versions installed simultaneously on Debian 12.

How can I verify the successful installation of Python 3.9 on Debian 12? 

Execute the command python3.9 --version to check the installed Python version. It should display the Python 3.9 version number.

Can I use pip to install Python packages with Python 3.9 on Debian 12? 

Yes, Debian 12 provides pip for Python 3.9 by default. Use pip3.9 to install packages specifically for Python 3.9.

What if the default Python version remains unchanged after installing Python 3.9 on Debian 12?

You can set Python 3.9 as the default version using the update-alternatives command. Consult Debian's documentation for detailed instructions.

Are there any considerations when working with system-level Python dependencies after installation? 

It is crucial to ensure that system-level Python dependencies are compatible with Python 3.9. Verify compatibility and reinstall if necessary.

Conclusion

One of the most well-known languages in computer science is Python. Every developer has worked in this language at some point. Rightfully so! Because it provides a vast array of areas. In this language, we may create both Web applications and machine learning algorithms.

To install Python 3.9 on Debian 12, we've walked you through each and every step, including examples. We even ran a basic hello world program in Python 3.9 shell as an example to get you started.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.