How to Install Latest Version Of Python 3 on CentOS 7

March 12, 2019


Python is a popular, stable, and well-performing programming language. Many different Linux distributions use it, including CentOS 7.

CentOS 7 uses Python 2.7.5, but as Python has updated to 3.7.2. , this can create challenges. If the default version of Python is updated, it can break base system components like the yum package manager.

This guide will walk you through how to install the most recent version of Python 3 on CentOS 7. We offer two options for installation on CentOS, via the SCL utility or from the source code.

how to install python 3 on centos

Note: Even though the latest version of Python is 3.7.2, this guide shows you how to install an earlier version for simplicity. For an advanced guide to installing Python 3.7.2 from source code, skip ahead to section 3.


  • Access to a user account with sudo privileges
  • A CentOS 7 system, with the extras repository enabled
  • The yum package manager, included by default
  • A terminal window/command line (Ctrl-Alt-F2)

Preparing CentOS

Step 1: Update the package manager

Before you begin, refresh the package listings. This helps ensure that yum is up to date.

Launch a terminal window, and enter:

sudo yum update

Allow the process to complete.

Step 2: Install the SCL utility (required for Option 1 installation)

The SCL, or Software Collections, is an open-source project. Its goal is to let you install and run multiple versions of the same software on the same system. SCL is an excellent workaround for CentOS 7, where we don’t want to interfere with the system version of Python.

Install SCL with:

sudo yum install centos-release-scl
install scl

Note: For more information on SCL, or to browse their software collection, please visit the developers’ website. Also, note that the latest version of Python available through the SCL project is 3.6. It can take time for newer software releases to populate through third-party repositories.

Option 1: Installing Python 3 With SCL

Step 1: Install Python 3.6

To install Python 3.6, enter the following into a terminal window:

sudo yum install rh-python36

Note: If you prefer, you can install previous releases as well. SCL maintains Python 3.6, 3.5, 3.4, 3.3, and 2.7. Please see the Software Collections page for more information.

Step 2: Verify Version

1. In a terminal, enter the following to verify and check your version of Python:

python ––version

The system should respond by displaying

Python 2.7.5

verify python version

The output shows that the installation hasn’t changed the base Python that CentOS relies on.

2. To verify the installation of Python 3.6, first launch Python in an SCL shell:

scl enable rh-python36 bash

This command places you in a shell where you can use your newer Python version.

3. Enter the following:

python ––version

It should now display:

Python 3.6.x

verify python version in scl shell

If you need to exit the shell, type <strong>exit</strong> and hit enter and drop to a standard command prompt.

Step 3: Install Development Tools

Developing in Python requires another software package, called Development Tools.

Install this package by entering:

sudo yum groupinstall “Development Tools”

Allow the process to complete.

install development tools

Step 4: Create a Virtual Environment

1. Start by creating a directory to store your new project:

mkdir ~/python_project

cd ~/python_project

You can rename the directory to anything you prefer.

2. If you haven’t already, launch the SCL Python shell:

scl enable rh-python36 bash

3. Create a new Python virtual environment:

python –m venv python_project_venv

4. Activate the virtual environment:

source python_project_venv/bin/activate

The command prompt should change to the name of the project you just created. You’re now working in Python 3.6.

create virtual envirnoment for new python project

Option 2: Installing Python 3 From Source Code

If you need a version of Python that is not supported through SCL, you can download a copy of the source code. This method requires additional software, plus extra steps to compile and install the Python package.

1. Start by installing the gcc, open-ssl-devel, and bzip2-devel packages:

sudo yum install gcc openssl-devel bzip2-devel
install gcc openssl bzip2 devel

2. Browse to a directory to download the files: cd usr/src

3. Download the Python version you want to install:

sudo wget
download python from source code

4. Extract the package:

sudo tar xzf Python-3.7.2.tgz

5. Compile the source code into an installation package:

cd Python-3.7.2.tgz
./configure ––enable–optimizations
make altinstall

The <strong>make</strong> command builds the installer package. The <strong>altinstall</strong> command instructs your system to create a second installation of this version of Python. Without it, the system would replace the default version of Python.

6. Verify the software version:

python3.7 –v

The system should display:

Python 3.7.2


This guide provided two different ways on how to install the latest version of Python3,  3.7.2 on CentOS 7. For the newer version of CentOS, check out our article on how to install Python on CentOS 8.

Remember that it is essential to create a second installation, so you don’t accidentally break the functionality of other tools that rely on the older Python 2.7.5.

With everything set, you can start with some basics scripts like getting the current time and date in Python.

Was this article helpful?
Sofija Simic
Sofija Simic is an aspiring Technical Writer at phoenixNAP. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Check Python Version in Linux, Mac, & Windows
October 1, 2019

Python is a popular programming language with different versions organized by release date...
Read more
How to Install Pip on CentOS 7
January 17, 2019

Pip Installs Packages (Pip) is a package management system that simplifies the process of installing and...
Read more
How to Install phpMyAdmin on CentOS 7
October 22, 2018

This guide is for users who have already configured a CentOS server and installed the Apache HTTP services...
Read more
How to Back Up & Restore a MySQL Database
October 22, 2018

A MySQL database has been lost, and you're scrambling to restore a copy from your last backup...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.