+
+
vim
+
+
cdn
perl
haiku
+
+
echo
+
+
chef
+
kali
terraform
elixir
+
+
+
+
+
+
css
+
+
+
+
neo4j
+
+
+
+
esbuild
+
rb
π
π
+
prettier
js
linux
+
jenkins
+
+
+
goland
nest
torch
+
+
+
+
+
jasmine
+
js
+
s3
cdn
+
grpc
+
+
+
cassandra
+
+
//
+
+
+
choo
haskell
cosmos
matplotlib
weaviate
tf
pip
+
+
nest
postgres
+
couchdb
Back to Blog
How to Install Python 3.12 on AlmaLinux
Linux AlmaLinux

How to Install Python 3.12 on AlmaLinux

Published Dec 16, 2023

Ready to bring the magic of Python 3.12 to your AlmaLinux server? This guide makes it a breeze. We'll update your system, add essential tools, and walk through downloading and installing Python.

3 min read
0 views
Table of Contents

Python 3.12 brings exciting new features and performance improvements. This guide will walk you through installing Python 3.12 on AlmaLinux from source, ensuring you have the latest version with all optimizations enabled.

Prerequisites

Before starting, ensure you have:

  • A fresh installation of AlmaLinux
  • Root or sudo access
  • Basic familiarity with the command line

Step 1: Update System Packages

First, update your system to ensure all packages are current:

sudo dnf update -y

System Package Update

This command updates all installed packages to their latest versions, ensuring compatibility and security.

Step 2: Install Development Tools

Python compilation requires several development tools and libraries. Install them with:

sudo dnf groupinstall "Development Tools" -y

Development Tools Installation

Additionally, install specific dependencies needed for Python:

sudo dnf install wget openssl-devel libffi-devel bzip2-devel -y

Dependencies Installation

These packages include:

  • wget: For downloading Python source code
  • openssl-devel: For SSL/TLS support
  • libffi-devel: For ctypes Python module
  • bzip2-devel: For bz2 compression support

Step 3: Download Python 3.12 Source Code

Navigate to a temporary directory and download the Python source:

cd /tmp
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz

Python Source Download

Extract the downloaded archive:

tar xzf Python-3.12.1.tgz
cd Python-3.12.1

Step 4: Configure and Compile Python

Configure the build with optimizations:

./configure --enable-optimizations

Python Configuration

The --enable-optimizations flag enables Profile Guided Optimization (PGO) and Link Time Optimization (LTO), resulting in a Python binary that’s 10-20% faster.

Compile Python using multiple CPU cores:

make -j$(nproc)

Python Compilation

The -j$(nproc) flag uses all available CPU cores, significantly speeding up compilation.

Step 5: Install Python 3.12

Install Python using altinstall to avoid overwriting the system Python:

sudo make altinstall

Python Installation

Using altinstall instead of install prevents replacing the default python3 binary, which could break system tools.

Step 6: Verify Installation

Check that Python 3.12 is installed correctly:

python3.12 -V

Python Version Verification

You should see:

Python 3.12.1

Step 7: Install pip for Python 3.12

Pip should be installed automatically. Verify with:

pip3.12 -V

Creating Virtual Environments

It’s best practice to use virtual environments for Python projects:

python3.12 -m venv myproject
source myproject/bin/activate

Installing Common Packages

With your virtual environment activated, install packages as needed:

pip install requests numpy pandas django flask

Setting Python 3.12 as Default (Optional)

If you want to use python3 to invoke Python 3.12:

sudo alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1

Troubleshooting Common Issues

Missing Dependencies

If you encounter errors during compilation, you might be missing dependencies:

sudo dnf install zlib-devel readline-devel tk-devel \
    sqlite-devel xz-devel gdbm-devel ncurses-devel

SSL Module Not Available

If the SSL module isn’t available, ensure OpenSSL development files are installed:

sudo dnf install openssl-devel

Then reconfigure and rebuild Python.

Permission Denied Errors

If you get permission errors during installation, ensure you’re using sudo for the installation step.

Performance Tips

Enable JIT Compilation

Python 3.12 includes experimental JIT compilation. While not enabled by default, you can experiment with it in future releases.

Use Built-in Optimizations

Python 3.12 includes numerous performance improvements:

  • Faster attribute access
  • Optimized error handling
  • Improved memory usage

Conclusion

You’ve successfully installed Python 3.12 on AlmaLinux! This latest version brings performance improvements, new syntax features, and better error messages. Whether you’re developing web applications, data science projects, or system scripts, Python 3.12 on AlmaLinux provides a robust and efficient platform.

Remember to always use virtual environments for your projects and keep your Python installation updated with the latest security patches.