June 7, 2025
Tutorials

How to Install Python on Debian 12

Install Python on Debian 12

Python is a popular high-level programming language used in various fields, including web programming, artificial intelligence, and data processing. It offers many standard libraries and packages that contain code written before for particular system functions and tasks. As Python is a dependency for many packages, Debian 12 and several other Linux distributions have it installed out of the box. In any case, you can install and manage different versions of Python with ease on your machine.

This guide will show you how to install Python on Debian 12 using various methods.

Overview

How to Install Python on Debian 12

You can perform the following steps in either order to successfully install Python on a Debian 12 machine:

Method 1: From the Default Debian Repository

The Debian repository includes a considerable selection of software packages, including Python. Unfortunately, the available packages are somewhat old. Should you wish to install Python, follow these simple steps to get it from the Debian repository:

Step 1: Update Debian Packages

Obtain the new listing of Debian packages by running:


sudo apt update

sudo apt update

Step 2: Install Python on Debian 12

Finally, execute the following command, and your system should be able to download Python from the Debian repository:


sudo apt install python3

sudo apt install python3

The system has the most recent version from the Debian repository, as noted in the output.

Step 3: Verification

To authenticate that you have Python installed, check which version is running:


python3 –version

That is the first method.

Method 2: From Source Code

The official website of Python contains numerous packages of Python source files. Therefore, for any version you desire, you can manually download the source package and install Python on your Debian 12 machine from the source code. Let’s consider below steps for installation through the source code:

Step 1: Install Required Dependencies

Now, install the required dependencies through the following command. This command will update the package storage list and install all listed libraries:


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

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

Step 2: Download Python’s Source Code File

Next, go to the official Python website and take the link to the latest source package. Download it using the following command:


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

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

At this point, we are downloading the source code file for the most up-to-date version of Python, which is “3.13.4”.

Instead, users can download the latest source code file from the website:

Download Python source code

Step 3: Extract Source Code

Furthermore, users can utilize the “tar -zxf” utility to unzip the downloaded file:


tar -zxf Python-3.13.4.tgz

tar -zxf Python-3.13.4.tgz

Step 4: Start Configuration Process

Now, go to the above directory “Python-3.13.4” through the “cd” command. After that, enter an appropriate command to start the configuration process:


./configure –enable-optimizations

./configure --enable-optimizations

As for further command options, the “–enable-optimizations” option is provided here to permit more optimization efforts to be made to improve the building process, alongside enhancing the performance of Python after the building process.

Step 5: Compile Source Code

Finally, start the compiling process through the make utility. You may also improve build speed by adding the flag -j along with a designated number.

make -j5

make -j5

Step 6: Install Python on Debian 12

Finally, install Python on the Linux distribution, Debian 12. To do so, utilize the below line after the compilation step:


sudo make altinstall

sudo make altinstall

This updates the previously installed versions of Python, but does not override the default system Python.

Step 7: Verify Python Installation

Finally, after authenticating the installation is successful, verify the version of Python with the below command:


python3.13 –version

python3.13 --version

That it.

How to Execute Python Scripts on Debian 12

After installing Python on a Debian system, access to the Python shell can be acquired by running the command:


python3

It can be observed that the Python shell was started:

By setting the variable to the following string, various scripts, such as:


print(“Hello Linux Users”)

print("Hello Linux Users")

To exit the Python shell, the following command can be used:


exit()

How to Fix a Debian 12 System Without Python

In general, it is not advised to uninstall Python from a Debian 12 system since various system packages or core utilities depend on it, including desktop environments like GNOME and KDE Plasma. However, if you are determined to do so, the command below will help you achieve that.


sudo apt autoremove python3* -y

If you have installed Python from the source, its uninstallation can easily be achieved by executing the following command:


sudo find /usr/local -depth -iname ‘python*’ -exec rm -rf {} \;

sudo find /usr/local -depth -iname 'python*' -exec rm -rf {} \;

Uninstalling Python system-wide will most likely lead to an inoperable system, including but not limited to being unable to use your desktop interface. For these types of problems, follow the instructions below:

To begin, you may reset the system, and you should get to see the terminal:

Debian 12 login

In the terminal, type in your Debian credentials to be able to access your account:

You may then update the DHCP client to re-initialize the internet on your terminal with this command:


sudo dhclient -r

Afterward, renew the network settings by executing the command to obtain a new IP address from the DHCP server:


sudo dhclient

Then, use the command for resolving broken packages and for resolving dependencies as follows:


sudo apt install -f

Now, proceed to install the desktop environment on your Debian 12 system by executing the following command:


sudo apt install task-gnome-desktop -y

Thus, with the execution of these commands, the additional dependencies such as Python with the GNOME login menu, as illustrated below, will be installed:

This concludes managing the installation of Python and its dependencies on the Debian 12 system.

Final Thoughts

This guide presented the streamlined installation methods for Python on Debian 12 systems. With systems running on Debian, you would find Python readily available for use. Nevertheless, for version 12, installation can be done through the official Debian repositories or, source code. It’s important to note that the default repositories contain an outdated version. To have the latest, specific versions, installation through source is recommended. To install Python on Debian 12, run sudo apt update && sudo apt install python3. Once the installation is complete, verify it by running python3 –version.

Frequently Asked Questions

Yes, Debian 12 comes with Python 3 pre-installed. You can verify it using python3 --version.
Run sudo apt update && sudo apt install python3 to ensure the latest version available in Debian's repo is installed.
Use sudo apt install python3-pip to install pip, the Python package manager.
Run pip3 --version to confirm that it's installed and working.
Yes, download the source from python.org, extract it, and follow the ./configure, make, and make install steps.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video