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

For developers working with Debian-based systems, understanding how to install Python 3.7 on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster is crucial, especially when dealing with legacy systems or projects that necessitate this specific Python version. Python 3.7, despite reaching its end of life in December 2022, continues to be a valuable asset due to its stability and feature set.

Key Features of Python 3.7:

  • Data Classes: These simplify creating classes primarily for storing values, enhancing code readability and efficiency.
  • Enhanced asyncio: With improvements in usability and performance, the enhanced asyncio module facilitates efficient asynchronous programming.
  • Context Variables: Introduced to manage variables in different contexts more effectively, context variables are particularly beneficial in asynchronous I/O operations.
  • Nanosecond Time Functions: Integrated into the time module, these functions are invaluable for applications that demand high-resolution timing.

Although Python 3.7 lacks official support, developers may install it on Debian systems as an alternative Python environment. This installation proves crucial for individuals maintaining legacy systems or needing Python 3.7 for particular testing purposes. The guide below offers step-by-step instructions for installing Python 3.7 on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, aiding developers in efficiently completing the installation process.

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

Update 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 Required PackagesFor Python 3.7 Installation on Debian

Next, we’ll install essential packages required for compiling Python from the source. These packages comprise development libraries and utilities necessary for 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: Download Python 3.7 Source 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: Extract Python Archive 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 installing, make sure to configure the dynamic linker run-time bindings. Skipping this essential step may cause issues.

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

Let’s verify the installation by checking the Python version to confirm that the installation of Python 3.7 was successful and ready for use.

python3.7 --version

You should see output similar to the following:

Python 3.7.16

Configure 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.

Register 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 essential. 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.


This guide has outlined the installation process of Python 3.7 on Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster, highlighting its historical significance and enduring relevance despite reaching end-of-life status. Through detailed steps, developers learn to download, compile, and set up Python 3.7 as an alternative environment, ensuring compatibility with legacy systems and specific libraries that necessitate this version. Consequently, this guide not only facilitates access to Python 3.7 when required but also underscores Python’s versatility and adaptability to various project and developer needs, all while supporting work with newer Python iterations.