How to Install Python 3.8 on Debian 10

Published on

3 min read

Install Python 3.8 on Debian 10 Linux

Python is one of the most widely used programming languages in the world. With its simple and easy to learn syntax, Python is a popular choice for beginners and experienced developers. Python is quite a versatile programming language. It can be used to build all kinds of applications, from simple scripts to sophisticated 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 parameters, f-strings support, and more . Python 3.8 is not available in the standard Debian 10 repositories.

This tutorial covers how to install Python 3.8 on Debian 10. We’ll 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 straightforward process and will only take a few minutes.

  1. Start by installing the packages necessary to build Python source:

    sudo apt updatesudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
  2. Download the latest release’s source code from the Python download page with wget or curl . At the time of writing this article, the latest release is 3.8.2:

    curl -O https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
  3. When the download is complete, extract the tarball :

    tar -xf Python-3.8.2.tar.xz
  4. Navigate to the Python source directory and run the configure script:

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

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

  5. Run make to start the build process:

    make -j 4

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

  6. Once the build is done, install the Python binaries by running the following command as a user with sudo access :

    sudo make altinstall

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

  7. At this point, Python 3.8 is installed on your Debian system and ready to be used. You can verify it by typing:

    python3.8 --version
    Python 3.8.2

Creating a Virtual Environment

Python virtual environment is a self-contained directory tree that includes a Python installation and a number of additional packages. It allows you to install Python modules in an isolated location for a specific project, rather than being installed globally. This way, you do not have to worry about affecting other Python projects.

In this example, we’ll create a new Python 3.8 project called my_app inside the user home directory.

First, create the project directory and switch to it:

mkdir ~/my_app && cd ~/my_app

From inside the project root run the following command to create a virtual environment named my_app_venv:

python3.8 -m venv my_app_venv

Activate the environment:

source my_app_venv/bin/activate

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

Within the virtual environment, you can use pip instead of pip3.8 and python instead of python3.8:

python -v
Python 3.8.1

Once you are done with your work to deactivate the environment, type deactivate, and you will return to your normal shell.

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 your Python 3 projects.

If you have any questions or feedback, feel free to comment below.