AlmaLinuxRHEL Based

How To Install Python on AlmaLinux 10

Install Python on AlmaLinux 10

Python stands as one of the most versatile and widely-adopted programming languages in today’s technology landscape. Whether you’re developing web applications, automating system tasks, or diving into machine learning projects, Python’s readable syntax and extensive library ecosystem make it an excellent choice for developers and system administrators alike.

AlmaLinux 10 represents the latest evolution of this enterprise-grade Linux distribution, offering enhanced security features, improved performance, and long-term stability that organizations demand. Installing Python on AlmaLinux 10 opens up a world of possibilities for development and automation workflows.

This comprehensive guide will walk you through multiple methods to install Python on AlmaLinux 10, from using the built-in package manager to compiling from source code. You’ll learn how to set up virtual environments, manage multiple Python versions, and optimize your installation for production use. By the end of this tutorial, you’ll have a fully functional Python environment ready for your development projects.

Prerequisites and System Requirements

Before diving into the Python installation process, ensure your AlmaLinux 10 system meets the necessary requirements and you have the appropriate access permissions. A successful Python installation requires several key components and system preparations.

Your AlmaLinux 10 system should have at least 2GB of RAM and 10GB of available disk space for a comfortable Python development environment. While Python itself doesn’t require significant resources, compilation from source and virtual environments can consume additional space.

Root or sudo access is essential for installing system packages and managing Python installations. Most installation methods require elevated privileges to modify system directories and install dependencies. Network connectivity is also crucial since you’ll be downloading packages from official repositories and potentially from Python’s official website.

Basic familiarity with Linux command-line operations will significantly enhance your experience following this guide. Understanding fundamental commands like cd, ls, wget, and package management concepts will make the installation process smoother and more intuitive.

Method 1: Installing Python Using DNF Package Manager

The DNF (Dandified YUM) package manager provides the most straightforward approach to installing Python on AlmaLinux 10. This method leverages pre-compiled packages from official repositories, ensuring compatibility and easy maintenance.

Updating the System

Begin by updating your AlmaLinux 10 system to ensure you have the latest security patches and package information. Execute the following commands in your terminal:

sudo dnf clean all
sudo dnf update -y

The system update process may take several minutes depending on your current package versions and internet connection speed. Once completed, enable the EPEL (Extra Packages for Enterprise Linux) repository to access additional Python packages:

sudo dnf install epel-release -y

Install essential development tools that will be useful for Python development and package compilation:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make -y

Installing Python from Official Repositories

AlmaLinux 10 repositories typically include multiple Python versions to accommodate different project requirements. Check available Python packages using:

sudo dnf list available | grep python3

Install the default Python 3 version along with essential development packages:

sudo dnf install python3 python3-devel python3-pip -y

This command installs Python 3, development headers, and the pip package manager simultaneously. The installation process automatically handles dependencies and ensures all components work together seamlessly.

Verify the installation by checking the Python version:

python3 --version
pip3 --version

Managing Multiple Python Versions

For projects requiring specific Python versions, install additional versions using DNF. AlmaLinux 10 repositories may include Python 3.9, 3.10, 3.11, and potentially newer versions:

sudo dnf install python3.10 python3.11 -y

Use the alternatives system to manage multiple Python versions and set a default:

sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
sudo alternatives --config python3

This approach allows you to switch between Python versions system-wide while maintaining individual version access through specific commands like python3.10 or python3.11.

Method 2: Installing Python from Source Code

Compiling Python from source code provides maximum flexibility and access to the latest features, optimizations, and security patches. This method is particularly valuable when you need cutting-edge Python versions or specific compilation flags.

Installing Build Dependencies

Source code compilation requires a comprehensive set of development tools and libraries. Install all necessary dependencies before proceeding:

sudo dnf install wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel -y

These packages provide essential compilation tools, SSL support, compression libraries, and database connectivity options. The comprehensive dependency installation ensures your compiled Python will have full functionality.

Verify that GCC is properly installed and accessible:

gcc --version
make --version

Downloading Python Source Code

Navigate to your preferred download directory and obtain the latest Python source code. Create a dedicated directory for the installation:

cd /opt
sudo mkdir python-source && cd python-source

Download Python 3.13.3 (or the latest stable version) from the official Python website:

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

Verify the download integrity by checking the file size and optionally downloading the corresponding checksum file from the Python website. Extract the downloaded archive:

sudo tar -xzf Python-3.13.3.tgz
cd Python-3.13.3

Compiling and Installing Python

Configure the build process with optimization flags for enhanced performance. The configuration step prepares the build environment and checks for required dependencies:

sudo ./configure --enable-optimizations --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions

The --enable-optimizations flag enables Profile Guided Optimization (PGO), which can improve Python performance by 10-20% but increases compilation time significantly. The --with-system-ffi option uses the system’s libffi library for better integration.

Determine the number of CPU cores for parallel compilation:

nproc

Compile Python using all available CPU cores to speed up the process:

sudo make -j $(nproc)

The compilation process typically takes 15-30 minutes depending on your system specifications. Monitor the process for any error messages that might indicate missing dependencies or configuration issues.

Install the compiled Python using altinstall to avoid overwriting the system Python:

sudo make altinstall

The altinstall option installs Python with version-specific names (e.g., python3.13) while preserving the system’s default Python installation.

Post-Installation Configuration

Create symbolic links for easier access to your compiled Python version:

sudo ln -sf /usr/local/bin/python3.13 /usr/local/bin/python3-custom
sudo ln -sf /usr/local/bin/pip3.13 /usr/local/bin/pip3-custom

Update your PATH environment variable to prioritize your custom Python installation by adding the following line to your ~/.bashrc file:

export PATH="/usr/local/bin:$PATH"

Reload your shell configuration:

source ~/.bashrc

Installing Python Package Manager (pip)

The pip package manager is essential for installing and managing Python packages from the Python Package Index (PyPI) and other repositories. Modern Python installations typically include pip automatically, but understanding its configuration and usage is crucial.

Verify pip installation for your Python versions:

python3 -m pip --version
python3.13 -m pip --version

If pip is missing from any Python installation, install it manually using the get-pip.py script:

wget https://bootstrap.pypa.io/get-pip.py
python3.13 get-pip.py --user

Upgrade pip to the latest version for all Python installations:

python3 -m pip install --upgrade pip
python3.13 -m pip install --upgrade pip

Configure pip for enterprise environments by creating a pip configuration file at ~/.pip/pip.conf:

[global]
index-url = https://pypi.org/simple/
trusted-host = pypi.org
timeout = 60

Install essential Python packages commonly used in development environments:

python3 -m pip install virtualenv requests numpy pandas matplotlib

Creating and Managing Virtual Environments

Virtual environments provide isolated Python spaces that prevent package conflicts and enable project-specific dependency management. This practice is considered essential for Python development workflows.

Understanding Virtual Environments

Virtual environments solve the common problem of dependency conflicts between different Python projects. Each virtual environment maintains its own package installation directory, allowing projects to use different versions of the same package without interference.

Creating isolated environments becomes particularly important when working with multiple projects that require different package versions or when testing code against various dependency combinations. Virtual environments also prevent accidentally modifying system-wide Python packages that might break system tools.

Creating Virtual Environments

Use the venv module (included with Python 3.3+) to create virtual environments:

python3 -m venv myproject-env

For source-compiled Python versions, specify the full path:

/usr/local/bin/python3.13 -m venv myproject-env-313

Create virtual environments in a dedicated directory for better organization:

mkdir ~/venvs
cd ~/venvs
python3 -m venv development
python3 -m venv testing
python3 -m venv production

Managing Virtual Environments

Activate a virtual environment to begin using it:

source ~/venvs/development/bin/activate

Once activated, your command prompt will change to indicate the active environment. Install packages specific to this environment:

(development) $ pip install django flask requests

Create a requirements.txt file to document project dependencies:

(development) $ pip freeze > requirements.txt

Deactivate the virtual environment when finished:

(development) $ deactivate

Remove virtual environments by simply deleting their directories:

rm -rf ~/venvs/old-project

Installing Specific Python Versions

Different projects often require specific Python versions for compatibility reasons. This section covers installing and managing multiple Python versions on AlmaLinux 10.

Python 3.10 Installation

Python 3.10 introduced significant performance improvements and new syntax features. Install Python 3.10 from source if not available in repositories:

cd /opt/python-source
sudo wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz
sudo tar -xzf Python-3.10.8.tgz
cd Python-3.10.8
sudo ./configure --enable-optimizations --prefix=/opt/python310
sudo make -j $(nproc)
sudo make altinstall

Create a convenient access point:

sudo ln -sf /opt/python310/bin/python3.10 /usr/local/bin/python3.10
sudo ln -sf /opt/python310/bin/pip3.10 /usr/local/bin/pip3.10

Python 3.11 Installation

Python 3.11 offers substantial performance improvements, with some workloads running 10-60% faster than previous versions. Follow the same compilation process with version 3.11 source code:

cd /opt/python-source
sudo wget https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tgz
sudo tar -xzf Python-3.11.5.tgz
cd Python-3.11.5
sudo ./configure --enable-optimizations --prefix=/opt/python311
sudo make -j $(nproc)
sudo make altinstall

Python 3.13 Installation

Python 3.13 represents the cutting edge of Python development, featuring improved error messages, enhanced debugging capabilities, and continued performance optimizations. The installation process follows the same pattern as previous versions.

When installing multiple Python versions, consider using different prefix directories to avoid conflicts and maintain clean separation between installations.

Verification and Testing

Thorough testing ensures your Python installation functions correctly and meets your development requirements. Verify installations across all installed Python versions.

Check Python interpreter functionality:

python3 -c "print('Hello, AlmaLinux 10!')"
python3.10 -c "import sys; print(sys.version)"
python3.13 -c "import platform; print(platform.platform())"

Test package installation and import capabilities:

python3 -m pip install requests
python3 -c "import requests; print(requests.__version__)"

Run a comprehensive system test script:

#!/usr/bin/env python3
import sys
import os
import subprocess

def test_python_installation():
    print(f"Python version: {sys.version}")
    print(f"Executable location: {sys.executable}")
    print(f"Python path: {sys.path}")
    
    # Test standard library imports
    modules = ['json', 'sqlite3', 'ssl', 'urllib', 'xml']
    for module in modules:
        try:
            __import__(module)
            print(f"✓ {module} imported successfully")
        except ImportError as e:
            print(f"✗ Failed to import {module}: {e}")

if __name__ == "__main__":
    test_python_installation()

Performance benchmarking helps verify optimization effectiveness:

python3 -m timeit -s "import math" "math.factorial(100)"

Advanced Configuration and Optimization

Production Python environments benefit from advanced configuration and performance tuning. These optimizations enhance security, performance, and maintainability.

Configure Python for production use by setting appropriate environment variables in /etc/environment:

PYTHONPATH=/opt/custom-libs
PYTHONHASHSEED=random
PYTHONIOENCODING=utf-8

Enable Python’s built-in debugging and profiling capabilities by installing additional tools:

python3 -m pip install py-spy memory-profiler line-profiler

Configure system-wide Python policies using /etc/python3/sitecustomize.py:

import sys
import warnings

# Filter deprecation warnings in production
if not sys.flags.debug:
    warnings.filterwarnings('ignore', category=DeprecationWarning)

# Set default encoding
import locale
locale.setlocale(locale.LC_ALL, 'C.UTF-8')

Implement security hardening by restricting Python module imports and setting appropriate file permissions on Python installations.

Troubleshooting Common Issues

Understanding common installation problems and their solutions helps maintain stable Python environments.

Dependency Resolution Problems: Missing development packages often cause compilation failures. Ensure all required -devel packages are installed:

sudo dnf install *-devel openssl-devel libffi-devel

Permission Issues: Installation failures due to insufficient permissions require sudo access or proper user privileges. Verify ownership of installation directories:

ls -la /usr/local/bin/python*
sudo chown root:root /usr/local/bin/python3.13

SSL Certificate Problems: SSL-related errors during package installation often indicate missing or outdated certificates:

sudo dnf update ca-certificates
python3 -m pip install --trusted-host pypi.org --trusted-host pypi.python.org package_name

Path and Environment Variables: Incorrect PATH configuration prevents Python discovery. Verify and correct PATH settings:

echo $PATH
which python3
whereis python3

Memory and Performance Issues: Large compilation tasks may exhaust system memory. Monitor resource usage and adjust parallel compilation settings:

free -h
sudo make -j 1  # Use single-threaded compilation for low-memory systems

Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing Python programming language on your AlmaLinux OS 10 system. For additional help or useful information, we recommend you check the official Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button