How To Install Python 3 On CentOS 7 Using SCL


Python is an incredible programming language that is ideal for both beginners and well-versed developers. The language is versatile which means it can be used to perform various functions such as building games, writing small scripts, creating algorithms for machine learning, analyzing data, developing websites, and more.

Some of the most popular websites and applications developed using Python include DropBox, YouTube, Quora, Reddit, Pinterest, and Instagram.

This tutorial will show you how to install the latest version of Python on your CentOS 7 system. The installation will utilize the Software Collections (SCL) and distribution default Python 2.7. We’ll also help you learn some basics and create a virtual environment for Python to streamline its usage.

Ready? Let’s get started!

Step 1 Enabling Software Collections (SCL)

The first thing when installing Python on CentOS 7 is enabling the Software Collections. The Software Collection is a reliable, community project designed to allow developers to install, build, and utilize numerous software versions on a single system without compromising the performance of the system default modules.

When the SCLs are enabled they grant you unfettered permissions to use the latest version of services and programming languages that may not be present in the main repositories.

Run the command below to install the release files for SCL. The release file is a component of  CentOS additional repository.

$ sudo yum install centos-release-scl

Step 2 Installing Python 3

You have enabled the SCL and should be able to access the Software Collections repository. This means you can implement any version of Python 3. At the time of writing Python 3 collection had the following 3.x versions:

  • Python 3.6
  • Python 3.5
  • Python 3.4
  • Python 3.3

Our tutorial will focus on Python version 3.6. To install this Python version, run the command below:

$  sudo yum install rh-python36

The application will not take long to install. Once the installation is complete, you can now proceed with the usage of Python.

Step 3 Using Python 3

First, run the command below to verify the version of Python 3:

$ python --version

This will give you the output below:

Python 2.7.5

This is because Python 2.7 manifests as the default application on the current shell. However, we installed Python 3.6 and that is what we intend to use. Now to access this version, we should make use of the SCL tool to launch a different shell instance:

$ scl enable rh-python36 bash

The command above will call /opt/rh/rh-python36/enable; a script that changes the variables of a shell environment. Now, if you verify your Python version once again:

$ python --version

You will get the output below:

$ Python 3.6.3

However, this does not change the core settings. Python 3.6 will function as a main Python version in the current shell environment. In case you exit the current shell session and enter a new one, Python 2.7 will still manifest as the default version.

Step 4 Installing The Python Development Tools

Development tools help you build Python Modules, Now, run the command below to install all the required libraries and tools:

$ sudo yum groupinstall 'Development Tools'

Step 5 Creating Python Virtual Environment

The Python virtual environment permits you to configure Python packages in a secure location. The environment offers unprecedented control over your system for Python projects. It ensures that every project has its own dependencies and that it will not interfere with other projects.

First, fashion a new project directory, then switch to the directory:

$ mkdir ~/my_new_project
$cd ~/my_new_project

Next, run the command below to enable Python:

$ scl enable rh-python36 bash

Now, run the command below from within the new Project root to fashion a new environment called my_project_venv:

$ python -m venv my_project_venv

Execute the command below to enable the new virtual environment:

$source my_project_venv/bin/activate

Once the virtual environment is activated, your shell prompt should be prefixed with the title of the virtual environment.

$ (my_project_venv) user@host:~/my_new_project$

The prefix indicates that the Python virtual environment my_project_venv is currently active. This means that if you create new programs in this environment, they will only utilize the settings and packages specific to this environment.

By now, the Python virtual environment is set and ready to use.


That’s it! You have successfully installed Python 3.6 on your CentOS system and it should be easy to utilize  Python programming language to develop a new application.

Check out these top 3 Linux hosting services

Was this article helpful?