How to Install Python 3.12 on Debian 11

Choose a different version or distribution

Introduction

Before we begin talking about how to install Python 3.12 on Debian 11, let's briefly understand – What is Python?

Python is a popular programming language known for its versatility and readability. It is widely used in web development, data analysis, artificial intelligence, and scientific computing.

Python's syntax is clean and easy to understand, making it ideal for beginners and seasoned programmers alike. With a vast library of tools and resources, Python offers endless possibilities for creating diverse applications.

In this tutorial, you will install Python 3.12 on Debian 11. We will also address a few FAQs on how to install Python 3.12 on Debian 11.

Advantages of Python 3.12

  1. Enhanced f-strings- Supports multi-line expressions and comments for more expressive string formatting.
  2. Improved error messages- Provides helpful suggestions and guidance for better debugging.
  3. Optimizations- Includes inlined comprehensions for faster Python performance.
  4. New syntax for type variables- Allows annotating generics for clearer code with static type checkers.
  5. Formal verification for built-in hash functions- Ensures enhanced security through formal verification of hash functions like SHA and MD5.

Manually build Python 3.12 from the source code

Update System

Initially, make sure your system is updated by executing,

apt update -y

apt upgrade -y

Install Required Dependencies

Install the required packages in order to build Python from scratch.

apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

Download Python Source Code

To obtain the source code, go to the Python downloads page. Next, download the source using wget.

wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

Now, Extract the Archive,

tar -xf Python-3.12.0.tgz

Configure and Build,

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

Build Python,

make -j 8

The number of CPU cores you wish to set aside for the build process should be substituted for 8.

Install Python

make altinstall

It won't replace the system's default Python interpreter if altinstall is used instead of install, which could lead to system tool malfunctions.

Verify Installation

Verify that Python 3.12 has been installed properly.

python3.12 --version

Output:

This should output the Python version you just installed.

FAQs to Install Python 3.12 on Debian 11

Is Python 3.12 available in the default Debian 11 repositories?

No, Python 3.12 is not available in the default Debian 11 repositories. You need to add a third-party repository to install it.

How do I add the Python 3.12 repository to Debian 11?

You can add the Python 3.12 repository by running the command sudo add-apt-repository ppa:deadsnakes/ppa in the terminal.

How do I update the package list after adding the repository?

After adding the repository, you need to update the package list by running the command sudo apt-get update in the terminal.

How do I switch between different versions of Python on Debian 11?

You can switch between different versions of Python on Debian 11 by running the command sudo update-alternatives --config python3 and selecting the desired version.

Are there any known issues with installing Python 3.12 on Debian 11?

No, there are no known issues with installing Python 3.12 on Debian 11. However, it is always a good idea to check the official documentation and any available release notes for any known issues or compatibility problems.

Are there any dependencies required to install Python 3.12 on Debian 11?

Yes, Python 3.12 requires several dependencies, including libssl-dev, libgdbm-dev, and libreadline-dev. These dependencies will be installed automatically when you run sudo apt-get install python3.12.

Are there any specific configuration steps required for Python 3.12 on Debian 11?

No, there are no specific configuration steps required for Python 3.12 on Debian 11. Python 3.12 should work out of the box after installation.

Conclusion

We hope this tutorial helped you understand how to install Python 3.12 on Debian 11.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.