How to Install Python 3.12 on Linux Mint 21 or 20

Python 3.12 emerges as a noteworthy upgrade in the world of programming, introducing an array of enhancements and new features to the Python language. This guide will specifically focus on demonstrating how to install Python 3.12 on Linux Mint 21 or 20. With Python 3.12, developers and enthusiasts can unlock a more efficient and powerful coding experience.

The version brings with it not just improvements but also a series of changes that are set to redefine how Python is used and perceived.

Key Features of Python 3.12.0:

  • Enhanced f-string parsing: Increased flexibility in f-string parsing to include previously unavailable features.
  • Buffer protocol in Python code: This addition aids in more effective memory management.
  • New debugging/profiling API: Simplifies the process of pinpointing and solving performance-related issues.
  • Isolated subinterpreters with separate GILs: Offers improved concurrent execution.
  • Improved error messages: Now includes suggestions for exceptions, particularly those caused by common typos.
  • Linux perf profiler support: Enables more detailed performance tracing by reporting Python function names.
  • General performance upgrades: An approximate 5% boost in performance owing to various optimizations, including BOLT binary optimizer support.

Type Annotations:

  • New syntax for generic classes: Refines and simplifies the way generic classes are annotated.
  • Override decorator for methods: Enhances the clarity in method overrides with a new decorator.

Deprecations:

  • Removal of outdated elements: Certain elements like wstr, wstr_length in Unicode objects’ C implementation, along with modules like smtpd and distutils, have been deprecated.
  • SyntaxWarning for invalid backslash escapes: Now issues a warning for improper escape sequences in strings.
  • Altered integer internal representation: Prepares for future performance enhancements by modifying the way integers are internally handled.

As we transition into the technical aspects, it’s important to note that installing Python 3.12 on Linux Mint is a seamless process. This step ensures that users can fully utilize the new features and improvements brought about by this update. The following sections will guide you through the installation process, ensuring a smooth and efficient setup.

Install Python 3.12 on Linux Mint 21 or 20 via APT PPA

Step 1: Update Linux Mint System Before Installing Python 3.12

To start, it’s crucial to update your Linux Mint system. This step ensures compatibility and reduces potential conflicts during the Python 3.12 installation.

Open your terminal and run the following command to update the system:

sudo apt update

Then, upgrade any outdated packages with this command:

sudo apt upgrade

Step 2: Add Python 3.12 PPA to Linux Mint

Linux Mint users can conveniently install Python 3.12 via the “deadsnakes” team’s Launchpad PPA. This repository is regularly updated with the latest Python releases.

Execute the command below to add the stable Python 3.12 PPA:

sudo add-apt-repository ppa:deadsnakes/ppa -y

For enthusiasts seeking the bleeding-edge version of Python 3.12, consider adding the Python Nightly PPA. However, this version is typically less stable and is recommended primarily for development purposes:

sudo add-apt-repository ppa:deadsnakes/nightly -y

Step 3: Update APT Index After Adding Python 3.12 PPA

Following the addition of the PPA, it’s essential to refresh the APT package index. This action ensures your system recognizes the new repository. Use this command to update:

sudo apt update

Step 4: Install Python 3.12 on Linux Mint via APT

With the repository set up, you can now install Python 3.12. Run the following command to begin the installation:

sudo apt install python3.12 -y

To verify the installation and check the version of Python installed, use:

python3.12 --version

The output should display the installed Python version, like:

Python 3.12.x

If Python 3.12 is not the default version, see the end section switching default python versions.

Step 4: Install Python 3.12 Additional Packages

sudo apt install python3.12-{tk,dev,dbg,venv,gdbm,distutils}

If you’re searching for a specific Python 3.12 module, use the apt search command to list all available packages:

apt search python3.12-*

For an all-encompassing installation, including all extras, execute:

sudo apt install python3.12-full

Step 5: Install Python Alternative Versions if Required

Optionally, for a more extensive setup, install additional Python 3.12 modules. The command below includes a comprehensive range, but you can omit any unnecessary modules:

sudo apt install python{2.7,3.7,3.8,3.9,3.10,3.11,3.12}

Be sure to adjust the command to include only the necessary versions. It’s advisable to avoid installing multiple versions, particularly those no longer supported (EOL).

Install Python 3.12 on Linux Mint 21 or 20 from Source

Step 1: Download Python 3.12 in Linux Mint

Begin by visiting Python’s official download page to get the latest version of Python 3.12. This approach applies to any version since you’re compiling it directly.

Use the wget command to download the Python 3.12 archive:

wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz

The link may change, so ensure you use the current one. The example above is illustrative. Once downloaded, extract the archive and be mindful to use the correct version number for newer releases:

Step 2: Install Necessary Packages for Python 3.12

Install dependencies required to compile Python 3.12:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev pkg-config make -y

Step 3: Configure Python 3.12 Build Environment

Go to the directory where Python source code is extracted:

cd Python-3.12.{version}/

Execute the ./configure script with optimization and shared library options:

./configure --enable-optimizations --enable-shared

This script checks for all dependencies. Using --enable-optimizations optimizes Python by running extensive tests, enhancing Python’s performance at the expense of a longer build time.

Step 4: Compile Python 3.12 in Linux Mint

Proceed to compile Python using make. To speed up the process, utilize multiple CPUs with the -j flag:

make -j <number of CPUs>

For instance, if your system has 6 CPUs, you can use make -j 6 to compile faster.

Step 5: Verify Python 3.12 Installation

Check your Python 3.12 installation and its build version:

python3.12 --version

This command should display the installed version, confirming successful installation.

Switch Default Python Versions on Linux Mint 21 or 20

Step 1: Create Symbolic Links for Each Python Version

To manage multiple Python versions on Linux Mint, start by creating symbolic links for each version. This process involves associating the ‘python’ command with different Python binaries.

Here’s how to set it up for various versions, including Python 3.12:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 4
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 5
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 7

Adjust the commands to reflect the Python versions installed on your system.

Step 2: Display Installed Python Versions

To see all Python versions installed and their selection numbers, use:

sudo update-alternatives --config python

Step 3: Change the Default Python Version

To switch the default version, for instance to Python 3.12, input the respective selection number from the list provided in the previous step. Suppose Python 3.12 corresponds to number 7, execute:

sudo update-alternatives --config python

Then select ‘7’ when prompted. You’ll see a confirmation message like:

update-alternatives: using /usr/bin/python3.12 to provide /usr/bin/python (python) in manual mode

Step 4: Confirm the New Default Python Version

Verify that Python 3.12 is now the default version by re-running the command to list alternatives:

sudo update-alternatives --config python

Look for the asterisk (*) next to Python 3.12, confirming it as the new default version.

Conclusion

In this guide, we’ve navigated the essential steps to efficiently install and manage Python 3.12 on Linux Mint. From updating your system, and installing Python 3.12 via PPA or from source, to expertly switching between different Python versions, each step was crafted to enhance your Python experience.

Remember, keeping your system updated and cautiously managing multiple Python versions are key practices for optimal performance and stability. As you embark on your Python projects, these strategies will ensure you’re well-equipped to leverage the full potential of Python 3.12 in your development endeavors.

Leave a Comment