How to Install Python 3 and pip on RHEL 7

RHEL 7 ships with Python 2.7 as the system default, and that version is deeply embedded in system utilities such as yum itself. Replacing or removing the system Python will break critical OS tooling, so the correct approach on RHEL 7 is to install Python 3 alongside Python 2 without disturbing the system default. Red Hat provides two well-supported paths for this: Software Collections (SCL) through the official rhscl channel, and the IUS (Inline with Upstream Stable) community repository. This guide covers both methods, explains how to make Python 3 the default for your own work without affecting the system, and shows you how to manage packages with pip3.

Prerequisites

  • RHEL 7 server with root or sudo access
  • An active RHEL subscription (for SCL method) or internet access to add IUS repo
  • Basic familiarity with the command line
  • At least 200 MB of free disk space

Step 1: Check What Python Versions Are Already Installed

Before installing anything, audit what is already present on the system:

# Check the system default Python (usually 2.7)
python --version
python2 --version

# Check if Python 3 is already available
python3 --version 2>/dev/null || echo "Python 3 not found"

# List all python binaries on the system
ls -la /usr/bin/python* /usr/local/bin/python* 2>/dev/null

Do not modify or alias the python command — it is used by yum, firewalld, and other critical RHEL 7 system components.

Step 2A: Install Python 3 via Software Collections (SCL)

Software Collections is Red Hat’s official mechanism for providing newer language runtimes without replacing system packages. SCL installs Python 3 into /opt/rh/ and activates it on demand using scl enable.

First, enable the SCL repository. On a registered RHEL 7 system:

sudo subscription-manager repos --enable rhel-server-rhscl-7-rpms

On a CentOS 7 or unregistered system, install from the centos-release-scl package:

sudo yum install -y centos-release-scl

Now install Python 3.6 (the most stable SCL Python 3 release for RHEL 7):

sudo yum install -y rh-python36

For Python 3.8:

sudo yum install -y rh-python38

Activate the SCL environment for your current shell session:

scl enable rh-python36 bash

Once inside the SCL shell, python3 and pip3 refer to the SCL Python:

python3 --version
# Python 3.6.12

which python3
# /opt/rh/rh-python36/root/usr/bin/python3

To use Python 3 in a shell script without requiring interactive scl enable:

#!/bin/bash
source /opt/rh/rh-python36/enable
python3 your_script.py

Step 2B: Install Python 3 via the IUS Repository (Alternative)

The IUS repository provides Python 3 builds that install directly as system-wide commands (e.g., python36u, python3) without requiring scl enable. This is simpler for day-to-day use but comes from a community rather than Red Hat.

# Install EPEL first
sudo yum install -y epel-release

# Add the IUS repository
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm

# Install Python 3.6 from IUS
sudo yum install -y python36u python36u-pip python36u-devel

# Verify
python3.6 --version
pip3.6 --version

IUS packages use versioned binaries (python3.6, pip3.6) to avoid conflicting with any other Python 3 installations. You can create a python3 alias or symlink as shown in Step 4.

Step 3: Verify pip3 and Upgrade It

Both installation methods include pip3. Verify it is working and upgrade it to the latest version available for your Python 3 release:

# Check pip version
pip3 --version
# pip 9.0.3 from /opt/rh/rh-python36/root/usr/lib/python3.6/site-packages (python 3.6)

# Upgrade pip itself (always recommended before installing packages)
pip3 install --upgrade pip

# Verify the upgrade
pip3 --version

If you see a permissions error, you are trying to upgrade into the system site-packages. Use --user or a virtual environment (covered in the next tutorial) instead:

pip3 install --upgrade pip --user

Step 4: Configure the alternatives System

The alternatives system (also called update-alternatives on some distributions) manages multiple versions of the same command. You can register Python 3 with alternatives so you can switch between versions cleanly without hard-coding paths.

# Register Python 3.6 with alternatives (priority 1)
sudo alternatives --install /usr/local/bin/python3 python3 
    /opt/rh/rh-python36/root/usr/bin/python3.6 1

# If you also install Python 3.8, register it with a higher priority
sudo alternatives --install /usr/local/bin/python3 python3 
    /opt/rh/rh-python38/root/usr/bin/python3.8 2

# Interactively select the active version
sudo alternatives --config python3

# Verify
python3 --version

Never register python (without the version suffix) with alternatives on RHEL 7 — doing so risks breaking yum and other system tools that depend on Python 2.7.

Step 5: Installing Packages with pip3

With Python 3 available, you can install third-party packages using pip3. There are three common installation scopes:

User-level installs (recommended for non-root users)

# Install a package for the current user only
pip3 install --user requests

# Packages are installed to ~/.local/lib/python3.x/site-packages/
# Binaries go to ~/.local/bin/ — add this to your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

System-wide installs (requires root)

# Install system-wide (use sparingly — virtual environments are preferred)
sudo pip3 install requests

Installing multiple packages at once

pip3 install --user requests flask gunicorn psycopg2-binary

Installing from a requirements file

pip3 install --user -r requirements.txt

Step 6: Useful pip3 Commands

These commands work regardless of whether you installed via SCL or IUS:

# List installed packages
pip3 list

# Show details about a specific package
pip3 show requests

# Check for outdated packages
pip3 list --outdated

# Upgrade a specific package
pip3 install --upgrade requests

# Uninstall a package
pip3 uninstall requests

# Generate a requirements file from current environment
pip3 freeze > requirements.txt

# Search PyPI for a package (deprecated in newer pip; use https://pypi.org instead)
pip3 search flask

Step 7: Make Python 3 the Default in Your Shell

If you work exclusively in Python 3 and want python to refer to Python 3 in your personal shell sessions without affecting the system, add an alias to your shell profile. This does not affect other users or system scripts.

# Add to ~/.bashrc
echo "alias python=python3" >> ~/.bashrc
echo "alias pip=pip3" >> ~/.bashrc
source ~/.bashrc

# Verify
python --version
# Python 3.6.12

Do not create a system-wide alias or symlink at /usr/bin/python → Python 3. That path is used by RHEL 7 system scripts that expect Python 2.7 behaviour.

Step 8: Install Python Development Headers (for Compiled Extensions)

Some pip packages (notably those that wrap C libraries like psycopg2, lxml, or cryptography) need to compile native extensions during installation. Install the development headers for your Python 3 version:

# For SCL Python 3.6
sudo yum install -y rh-python36-python-devel

# For IUS Python 3.6
sudo yum install -y python36u-devel

# Also ensure gcc and common build tools are present
sudo yum install -y gcc make openssl-devel libffi-devel

Installing Python 3 on RHEL 7 requires a deliberate approach because of the system’s dependency on Python 2.7. Whether you choose Software Collections for a fully supported Red Hat path or the IUS repository for simpler command-line access, the result is a clean, parallel Python 3 installation that coexists with the system Python without conflict. With pip3 available and the alternatives system configured, you are ready to manage Python packages and — as the next tutorial covers — create isolated virtual environments for each project.