Upgrade Python 2.7 to 3.6 and installing pip on CentOS 7

Installing Development Tools

Development tools are required for building Python modules. To install the necessary tools and libraries type:

sudo yum groupinstall 'Development Tools'

Enable Software Collections (SCL)

Software Collections , also known as SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages. By enabling SCL you will gain access to the newer versions of programming languages and services which are not available in the core repositories.

CentOS 7 ships with Python 2.7.5 which is a critical part of the CentOS base system. SCL allows you to install newer versions of python 3.x alongside the default python v2.7.5 so that system tools such as yum will continue to work properly.

To enable SCL, you need to install the CentOS SCL release file. It is part of the CentOS extras repository and can be installed by running the following command:

sudo yum install centos-release-scl

Installing Python 3.6 on CentOS 7

Now we will install Python 3.6, which is the latest version available at the time of writing. To do so type the following command on your CentOS 7 terminal:

sudo yum install rh-python36

Using Python 3

Once the package rh-python36 is installed, check the Python version by typing:

python --version
Python 2.7.5

You will notice that Python 2.7 is the default Python version in your current shell.

To access Python 3.6 you need to launch a new shell instance using the Software Collection scl tool:

scl enable rh-python36 bash

What the command above does is calling the script /opt/rh/rh-python36/enable, which changes the shell environment variables.

If you check the Python version again, you’ll notice that Python 3.6 is the default version in your current shell now.

python --version
Python 3.6.3

It is important to point out that Python 3.6 is set as the default Python version only in this shell session. If you exit the session or open a new session from another terminal Python 2.7 will be the default Python version.

Install pip

Now let’s install python-pip and any required packages:

yum -y install python-pip



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.