Python 3.8 on Debian 10

Python is one of the most widely used programming languages in the world. With its easy-to-learn syntax, Python is a popular choice for beginners and experienced developers alike. Python is quite a versatile programming language. It can be used to build all kinds of applications, from simple and complex machine learning algorithms.

Debian 10 includes Python version 3.7, which can be installed or updated using the apt tool.

At the time of writing, Python 3.8 is the latest major release of the Python language. It includes many new features, such as assignment expressions, positional-only arguments, f-string support, and more. Python 3.8 is not available in the standard Debian 10 repository.

This tutorial describes how to install Python 3.8 on Debian 10. We will also show you how to create a virtual environment.

Installing Python 3.8 on Debian 10

Building Python 3.8 on Debian is a relatively simple process that takes only a few minutes.

First install the packages needed to build the Python source code.

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

Use there wget or curl to download the latest version of the source code from the Python page strip. At the time of writing, the latest version is 3.8.2.

1
curl -O https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz

After the download is complete, extract the zip package.

1
tar -xf Python-3.8.2.tar.xz

Go to the Python source directory and run the configure script.

1
2
cd Python-3.8.2
./configure --enable-optimizations

The script performs a number of checks to ensure that all dependencies are present on the system. The -enable-optimizations option will optimize the Python binaries by running multiple tests, which will slow down the build process.

Run -make to start the build process.

1
make -j 4

Modify -j to correspond to the number of cores in the processor. You can find the number by typing nproc in the terminal.

Once the build is complete, run the following command as a user with sudo access to install the Python binaries.

1
sudo make altinstall

Please do not use the standard make install as it will overwrite the default system python3 binary.

So far, Python 3.8 is installed and ready to use on your Debian system. You can verify this by entering the following.

1
python3.8 --version
1
Python 3.8.2

Creating a Virtual Environment

A Python virtual environment is a separate directory tree that includes the Python binary and many other packages. It allows you to install Python modules in isolated locations for specific projects, rather than globally. This way, you don’t have to worry about affecting other Python projects.

In this example, we will create a new Python 3.8 project named my_app in the user’s home directory.

First, create the project directory and switch to it.

1
mkdir ~/my_app && cd ~/my_app

Run the following command from inside the project root to create a virtual environment named my_app_venv.

1
python3.8 -m venv my_app_venv

Activation environment.

1
source my_app_venv/bin/activate

Once activated, the shell prompt will be prefixed with the environment name. Starting with Python 3.4, the package manager for Python will be installed by default when creating the virtual environment pip.

In a virtual environment, you can use pip instead of pip3.8 and python instead of python3.8.

1
python -v
1
Python 3.8.1

When you are done deactivating the environment, type deactivate and you will be returned to the regular shell.

1
deactivate

Conclusion

We have shown you how to install Python 3.8 on Debian 10. You can now create a virtual environment and start developing Python 3 projects.