Feb 20, 2023 4 min read

How to Install Python 3.7 on Debian 11

Install Python 3.7 on Debian 11 Bullseye with this easy-to-follow tutorial for beginners. Get started with the latest version of Python today!

Install Python 3.7 on Debian 11 Bullseye
Table of Contents

Choose a different version or distribution

Introduction

By default, Debian 11 does not include Python 3.7 in its repository. To run specific applications or frameworks on Debian, you may need to install Python 3.7.

Python 3.7 is currently receiving security updates until June 2023, when it will be decommissioned. If you are developing applications, it is recommended that you upgrade to newer versions.

Why use Python?

There are many reasons why you might choose to use Python for your next project:

  1. Easy to learn: Python's syntax is easy to read and understand, making it a great language for beginners.
  2. Versatile: Python can be used for a wide range of applications, from web development to scientific computing.
  3. Large community: Python has a large and active community of developers, which means there are plenty of resources available online to help you learn and solve problems.
  4. Plenty of libraries: Python has a vast collection of libraries and modules, making it easy to perform complex tasks with minimal coding.
  5. Cross-platform: Python is available for multiple platforms, including Windows, macOS, and Linux, so you can write code on one platform and run it on another.

Now that you know a bit about Python and why you might want to use it, let's move on to installing Python 3.7 on Debian 11.

Update Debian to Install Python 3.7

Run a quick update before you start to make sure your system is updated to prevent conflicts during the tutorial and to practice proper system maintenance.

sudo apt update && sudo apt upgrade

Install Python 3.7

Download Python 3.7

Use the wget command to download the Python 3.7 archive once you have the download link.

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

The Python archive should be extracted. If you downloaded a newer version, don't forget to update the version number:

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

You can optionally transfer Python 3.7 to a suitable location, such as the /opt/ directory.

sudo mv Python-3.7.{version} /opt/

Next, install the dependencies necessary 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

Go to the directory

cd /opt/Python-3.7.{version}/

Execute the command ./configure -enable-optimizations.

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

Please take note that the script does a number of checks to ensure that all of your system's dependencies are present. The ./configure -enable-optimizations command will run numerous tests to optimize the Python binary, slowing down the build process.

It's time to compile the environment using the make command now that you have built and configured it.

make

If you have a powerful server, a useful tip is to specify the -j <number of cpu> as this can considerably enhance compiling speed. For instance, the VegaStack machine has 6 CPUs, and you can use all 6, or at the very least 4 to 5, to boost the speed.

make -j 6

Install Python binaries as shown below once the building is complete:

sudo make altinstall

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

After the installation, you should set up the dynamic linker run-time bindings:

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

Please take note to not omit this, or problems will arise. You must also substitute the path with your directory name and version.

By executing the following command, you can verify that Python 3.7 and the build version are both installed:

python3.7 --version

Create a Virtual Environment

The Python venv module is a virtual environment within the Python environment. It has a separate Python interpreter, libraries, and scripts from those established in other virtual environments. Any libraries you have installed on your operating system, such as those on your Debian system, should avoid interfering with your production environments and causing disruptions.

Create a simple Python project to check that Python 3.7 is installed and working properly.

Create the project directory first, then navigate there.

mkdir ~/test_app && cd ~/test_app

Run the following command within the project root directory to create a virtual environment for the test name test_app.

python3.7 -m venv test_app_venv

Next, enable the virtual environment as follows:

source test_app_venv/bin/activate

Now that the virtual environment has started, you are in the shell prompt terminal. This displays the environment's name that will be prefixed.

To leave the virtual environment, enter the following command:

deactivate

Install Python PIP 3.7

PIP 3.7 should be installed by default. Manually installing the package manager is another approach for PIP issues.

There are various methods for doing this. Here is one of the most widely used approaches.

Re-enter your environment and use the wget command to download get-pip.py.

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

Install the downloaded file next.

python3.7 get-pip.py

It is a good idea to look for updates after installation.

python3.7 -m pip install --upgrade pip

With the following command, you can now confirm that PIP 3.7 version is actually installed.

pip3.7 --version

FAQs to Install Python 3.7 on Debian 11

What are virtual environments in Python?

Virtual environments allow you to isolate different Python projects and their dependencies. They are useful for avoiding conflicts between the dependencies of different projects.

What is pip in Python?

pip is the package manager for Python, and it helps you install and manage packages. Pip allows you to easily install and manage packages and their dependencies, making it easier to manage your Python projects.

What is the difference between Python 3.6 and Python 3.7?

Python 3.7 introduced several new features and improvements over Python 3.6, including faster startup times, improved performance for built-in data types, better error messages, and more.

How do I check if Python 3.7 is installed?

To check if Python 3.7 is installed, you can run the following command:

python3.7 --version

This should output the version of Python 3.7 that is installed on your system.

Conclusion

Python is a versatile and easy-to-learn programming language that is widely used for a variety of applications. If you're running Debian 11 and want to install Python 3.7, the process is relatively straightforward.

By following the steps in this tutorial, you should be able to install Python 3.7 on your system with ease. Don't forget to keep your system up to date and use the latest version of Python for the best performance and security.

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