How to install Python 3.9 on Debian 10

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

Python 3.9 is the last major release of the Python language. It includes many new features such as new dict operators, new str features, IANA timezone support, and more.

In this article, we will show you how to install Python 3.9 on Debian 10.

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

Installing Python 3.9 on Debian 10

Compiling Python from source allows you to install the latest version of Python and customize build options. However, you won’t be able to support installing Python through the apt package manager.

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

  1. Install the dependencies required to build Python:
    sudo apt update
    sudo 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 source code from the Python download page using wget:
    wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
  3. After the download is complete, unpack the compressed archive:
    tar -xf Python-3.9.1.tgz
  4. Change to your Python source directory and run the configure script:
    cd Python-3.9.1
    ./configure --enable-optimizations

    The –enable-optimizations option optimizes the Python binary by running multiple tests. This slows down the build process.

    The script performs a series of checks to ensure that all dependencies are present on your system:

  5. Start the build process for Python 3.9:
    make -j 2

    To speed up the build, change the -j value to match the number of cores in your processor. You can find out the number by typing nproc.

  6. When the build process is complete, install the Python binaries by typing:
    sudo make altinstall

    We use altinstall instead of install because the default system python3 binary will be overwritten later.

That’s all. Python 3.9 is installed and ready to use. To test this, enter:

python3.9 --version

The output should show the Python version:

Python 3.9.1

Output

We showed you how to install Python 3.9 on your Debian 10 system. Now you can create a virtual environment and start developing your Python projects.

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

Sidebar