How to Install Python 3.7 on Debian 12, 11 or 10

Python 3.7 remains a significant version in the Python ecosystem, even though it reached its end of life in December 2022. Known for its robust features and stability, Python 3.7 has various use cases that make it relevant today, particularly for legacy systems and backward compatibility testing.

Key Features of Python 3.7 on Debian 12, 11 or 10

  • Data Classes: Simplified the creation of classes mainly used for storing values.
  • Enhanced asyncio: Improved usability and performance for asynchronous programming.
  • Context Variables: Introduced for better managing variables in different contexts, especially useful in asynchronous I/O.
  • Nanosecond Time Functions: Added to the time module, benefiting applications requiring high-resolution timing.

While Python 3.7 is no longer officially supported, it can still be installed as an alternative Python environment. This is particularly useful for developers working on projects that require this specific version.

The upcoming guide will focus on how to install Python 3.7 on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster. Whether you’re maintaining a legacy system or need this version for testing, our step-by-step instructions will ensure a smooth installation process.

Section 1: Install Python 3.7 via source on Debian 12, 11 or 10

Step 1: Updating Debian System Packages Before Python 3.7 Installation

Before diving into the installation process, ensuring your Debian system is up-to-date is crucial. By doing so, we can guarantee that the existing packages will be compatible with the ones we install.

Execute the following command to update your system:

sudo apt update && sudo apt upgrade

Step 2: Installing Essential Development Packages For Python 3.7 Installation on Debian

Next, we’ll install a collection of necessary packages for compiling Python from the source. These packages include development libraries and other utilities that will be utilized during the compilation process.

Run the following command to install these packages:

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

Step 3: Downloading Python 3.7 Source Code on Debian 12, 11 or 10

We can now download the Python 3.7 source code from the official Python website with the necessary packages installed. The final version and security bugfix release for 3.7 was 3.7.17, which has reached its life’s end (EOL) status.

Use the following command to download the source code:


Step 4: Extracting Python Archive and Organizing Files on Debian

After downloading the source code, we need to extract it using the tar command:

tar -xf Python-3.7.16.tar.xz

Step 5: Configure, Compile, and Install Python 3.7 on Debian 12, 11 or 10

Now, let’s navigate to the directory containing the Python source code. We’ll run the ./configure script with certain flags for optimization and enabling shared libraries.

Navigate to the directory and run the configure script:

cd /usr/local/share/python3.7
./configure --enable-optimizations --enable-shared

The --enable-optimizations flag instructs the script to perform several checks to ensure all dependencies are present, and optimizes the Python binary by running multiple tests. The --enable-shared flag builds shared libraries, which are essential for certain types of applications.

You may also consider using the --with-ensurepip=install flag to install the pip package manager alongside Python.

Now it’s time to compile the source code using the make command:


For faster compilation, especially on systems with multiple CPU cores, you can use the -j flag followed by the number of CPU cores you want to utilize. For example, if your system has 6 CPU cores, you could use 5 of them:

make -j 5

Once the compilation is complete, install the Python binaries. It’s recommended to use the make altinstall command to avoid overwriting the default Python binary in the system.

sudo make altinstall

After the installation, configure the dynamic linker run-time bindings. This is an essential step and should not be skipped; neglecting to do so may lead to issues.

sudo ldconfig /usr/local/share/python3.7

Finally, let’s verify the installation by checking the Python version. This step is crucial to confirm that Python 3.7 was successfully installed and is ready for use.

python3.7 --version

You should see output similar to the following:

Python 3.7.16

Note, do not skip this, or you will face issues. You must also replace the path with your directory name and version.

Confirm that Python 3.7 is installed and the build version by running the following command:

python3.7 --version

Section 2: Setting Python 3.7 as an Alternative Python Environment on Debian

This section will guide you through setting up Python 3.7.16 as an alternative Python environment. This allows you to use Python 3.7.16 alongside other Python versions installed from the apt repository, such as Python 3.10 or 3.11.

Registering Python 3.7 with the update-alternatives Tool on Debian 12, 11, or 10

The update-alternatives tool in Debian allows you to manage multiple versions of a program. We’ll use this tool to register Python 3.7 as an alternative Python environment.

First, let’s register Python 3.7 with the update-alternatives tool. The --install flag is used to register the program, followed by the path to the program, the name of the link group (in this case, Python), and the priority of this version.

Run the following command to register Python 3.7:

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 1

Configure the Python Environment on Debian

With Python 3.7.16 registered, you can now configure which Python environment to use by default. The update-alternatives tool provides a simple way to switch between different versions.

To configure the Python environment, use the following command:

sudo update-alternatives --config python

You’ll be presented with a list of Python versions registered with the update-alternatives tool. Each version is assigned a number. To select Python 3.7.16, enter the associated number and press Enter.

Verifying the Python Environment

After setting Python 3.7 as the default Python environment, verifying that the changes were successful is important. You can do this by checking the Python version.

Run the following command to check the Python version:

python --version

If the setup was successful, you should see Python 3.7.16 as the output.

Remember, you can always switch back to a different Python environment using the update-alternatives --config python command. This flexibility allows you to work with different Python versions depending on your project requirements.


In this guide, we’ve walked through installing Python 3.7 on Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster. We’ve discussed the importance of Python 3.7, its historical significance, and why developers might still need this version despite its end-of-life status.

We’ve detailed the steps to download, compile, and install Python 3.7 from the source and how to set it up as an alternative Python environment. This allows for flexibility and compatibility in development, especially when dealing with legacy systems or specific libraries that require Python 3.7.

In conclusion, while Python 3.7 has reached its end of life, it remains a valuable tool for certain use cases. By following this guide, developers can ensure they have access to this version when needed while maintaining the ability to work with more recent Python versions. This guide serves as a testament to Python’s versatility and adaptability, catering to a wide range of project requirements and developer needs.

Share to...