How to Install Python 3.7 on Debian 11 Bullseye


By default, Debian 11 Bullseye does not come with Python 3.7 in its repositories, but you may find you need to run some applications or frameworks on Debian; you may need to install Python 3.7 on your system.

Python 3.7 is currently being worked on for security releases until its end of life on the 6th month of 2023. However, it is advisable to upgrade to newer versions if you are developing applications.

In the following tutorial, you will learn how to download the latest archive version of Python 3.7, compile and install this version of Python on Debian 11 Bullseye using the command terminal.

Update Debian

Before you begin, run a quick update to ensure your system is up-to-date to avoid conflicts during the tutorial and good system maintenance.

sudo apt update && sudo apt upgrade

Install Python 3.7

Download Python 3.7

Once you have the download link, use the wget command to download the Python 3.7 archive.

Advertisement


wget https://www.python.org/ftp/python/3.7.13/Python-3.7.13.tar.xz

Extract the Python archive. Remember to change the version number if you downloaded a newer one:

tar -xf Python-3.7.{version}.tar.xz

Optionally, move Python 3.7 to a proper destination like the /opt/ directory.

sudo mv Python3.7.{version} /opt/

Now install the dependencies required to install Python 3.7.

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

Navigate to the directory

cd /opt/Python3.7.{version}/

Run the ./configure –enable-optimizations command.

./configure --enable-optimizations --enable-shared

Note, The script performs several checks to make sure all of the dependencies on your system are present. The ./configure –enable-optimizations will optimize the Python binary by running multiple tests, which will make the build process slower.

Advertisement


Now that you have built and configured the environment, it is time to compile it with the command make.

make

A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server. For example, the LinuxCapable machine has 6 CPUs, and I can use all 6 or at least use 4 to 5 to increase speed.

make -j 6

Once you have finished building, install Python binaries as follows:

sudo make altinstall

Note, it’s advised to use the make altinstall command NOT to overwrite the default Python 3 binary system.

See also  How to Install VSCodium on Debian 11/10

Next, after the installation, you need to configure the dynamic linker run-time bindings:

sudo ldconfig /opt/Python3.7.{version}

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

Advertisement


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

python3.7 --version

Example output:

How to Install Python 3.7 on Debian 11 Bullseye

Create a Virtual Environment

Python’s venv module is a virtual environment in a Python environment. The Python interpreter, libraries, and scripts installed into it are isolated from those established in other virtual environments. Any libraries installed on your operating system, such as those installed on your Debian system, to avoid clashing and disturbing your production environments.

To ensure Python 3.7 is installed correctly and functioning, create a quick Python project.

First, create the project directory and navigate to it.

mkdir ~/test_app && cd ~/test_app

Inside the project root directory, run the following command to create a virtual environment for the test name test_app.

Advertisement


python3.7 -m venv test_app_venv

Next, activate the virtual environment as follows:

source test_app_venv/bin/activate

After starting the virtual environment, you will now be in the shell prompt terminal. This will show the name of your environment that will be prefixed.

Example:

How to Install Python 3.7 on Debian 11 Bullseye

To exit the virtual environment, use the following command:

deactivate

Install Python PIP 3.7

By default, PIP 3.7 should be installed. An alternative method for PIP issues is installing the package manager manually.

This can be done in several ways. One of the most common is as follows.

Advertisement


Log back into your environment, then download get-pip.py using the wget command.

wget https://bootstrap.pypa.io/get-pip.py

Next, install the file downloaded.

python3.7 get-pip.py

Once installed, it is a good idea to check for upgrades.

python3.7 -m pip install --upgrade pip

Now verify the PIP 3.7 version installed with the following command.

pip3.7 --version

Example output:

How to Install Python 3.7 on Debian 11 Bullseye

Comments and Conclusion

In the tutorial, you have learned how to install Python 3.7 and create a virtual test environment on Debian 11 Bullseye desktop or server.

Advertisement


Overall, it is advised if you are in development to move to Python 3.10 in the future, but using Python 3.7 is still safe as the Python Software Foundation maintains 3.7 until the middle of 2023. Still, you must check for updates and re-install Python using the steps provided in the tutorial.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment