Jun 7, 2024 3 min read

How to Install Python 3.12 on Debian 12

Install Python 3.12 on Debian 12 with our step-by-step tutorial. Python is a known high-level language appreciated for its readability.

Install Python 3.12 on Debian 12
Install Python 3.12 on Debian 12
Table of Contents

Choose a different version or distribution

Introduction

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

Python is a high-level programming language known for its simplicity, readability, and versatility. Developed in the late 1980s, Python has grown to become one of the most popular languages.

Its syntax is easy to learn and use, making it suitable for beginners and experienced developers. Python is used for web development, data analysis, machine learning, and more.

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

Advantages of Python 3.12

  • Enhanced f-strings: More flexible string formatting options.
  • Improved error messages: Clearer errors with helpful suggestions.
  • Performance boosts: Faster code execution through comprehension inlining.
  • Linux profiling support: Better profiling tools for Linux environments.
  • Improved type hinting: Clearer code with enhanced type hinting capabilities.

Manually build Python 3.12 from the source code

Update System

Firstly, 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 12

Can I use pip3.12 to install packages for Python 3.12?

Yes, you can use pip3.12 to install packages for Python 3.12. You can run pip3.12 commands in your terminal to install packages.

Do I need to uninstall Python 3.11 before installing Python 3.12?

No, you do not need to uninstall Python 3.11 before installing Python 3.12. Both versions can coexist on your system.

How do I set Python 3.12 as the default Python version?

You can set Python 3.12 as the default Python version by running the command sudo update-alternatives --set python /usr/bin/python3.12 in your terminal.

Can I use Python 3.12 with my existing Python 3.11 projects?

Yes, you can use Python 3.12 with your existing Python 3.11 projects. Python 3.12 is backward compatible with Python 3.11, so you can run your existing projects without any issues.

Are there any known issues with Python 3.12 on Debian 12?

No, there are no known issues with Python 3.12 on Debian 12. Python 3.12 is a stable release and should work smoothly on Debian 12.

Can I install Python 3.12 using apt-get?

No, you cannot install Python 3.12 directly using apt-get on Debian 12, as it is not available in the default repositories. You need to download and compile the source code to install Python 3.12.

How do I remove Python 3.12 if I no longer need it?

You can remove Python 3.12 by running the command sudo apt-get purge python3.12 in your terminal. This will remove Python 3.12 and its dependencies from your system.

Conclusion

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

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

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - 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.