Python 3 is the most widely used language for web development, data science, machine learning, automation, and DevOps tooling. RHEL 9 ships with Python 3.9 by default, but newer versions (3.11, 3.12) are available from the AppStream repository and provide significant performance improvements — CPython 3.11 is 10–60% faster than 3.10 for most workloads. The Python ecosystem is accessed through pip, the package installer, and managed with virtual environments that isolate project dependencies. This guide covers installing Python 3.12 on RHEL 9 from the AppStream repository, configuring pip with trusted package sources, and verifying the installation.

Prerequisites

  • RHEL 9 with sudo/root access

Step 1 — Check Available Python Versions

dnf module list python3*

# Install the default Python 3 (currently 3.9 on RHEL 9)
dnf install -y python3

# Check available newer versions
dnf install -y python3.12 python3.12-pip

Step 2 — Install Python 3.12

dnf install -y python3.12 python3.12-pip python3.12-devel

# Verify installation
python3.12 --version
pip3.12 --version

# Create convenient aliases (optional — use alternatives for system-wide config)
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2

Step 3 — Upgrade pip

# Always upgrade pip before installing packages
python3.12 -m pip install --upgrade pip

pip --version

Step 4 — Install Common Python Packages

# Web frameworks
pip install flask django fastapi uvicorn

# HTTP client
pip install requests httpx

# Data processing
pip install pandas numpy

# Database drivers
pip install pymysql psycopg2-binary redis pymongo

# Utilities
pip install python-dotenv pydantic

Step 5 — Configure pip Securely

# /etc/pip.conf — system-wide pip configuration
[global]
; Only install from PyPI (the official package index)
index-url = https://pypi.org/simple/
trusted-host = pypi.org
              pypi.python.org
              files.pythonhosted.org

; Require SSL certificate verification (default but explicit)
cert = /etc/ssl/certs/ca-bundle.crt

; Disable automatic pre-release installation
pre = false

Step 6 — Verify Python Installation

python3.12 -c "
import sys
import ssl
print(f'Python: {sys.version}')
print(f'SSL: {ssl.OPENSSL_VERSION}')
print(f'Path: {sys.executable}')
"

Conclusion

Python 3.12 on RHEL 9 is installed from the official AppStream repository, ensuring RHEL-supported packages with security backports. For project dependency management, always use virtual environments (python3 -m venv) rather than installing packages system-wide — system-wide pip installs can break OS tools that depend on specific package versions. The pip.conf configuration enforcing HTTPS and the official PyPI index protects against supply chain attacks from compromised or typosquatted packages.

Next steps: How to Use Python Virtual Environments on RHEL 9, How to Deploy a Django Application on RHEL 9, and How to Deploy a Flask Application on RHEL 9.