CentOS

Install Python 3 on CentOS 7

In this article, I will show you how to install Python 3.x, mainly Python 3.4, Python 3.5, Python 3.6 along with PIP for Python 3.4, Python 3.5, and Python 3.6 respectively on CentOS 7. Let’s get started.

Adding Package Repository

Python 3 is not installed by default in CentOS 7. Python 3 is not available in the official package repository of CentOS 7 as well. But we can add Inline Upstream Stable (IUS) package repository on CentOS 7 to install Python 3.

First update the yum package repository cache of your CentOS 7 machine with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Now install yum-utils package with the following command:

$ sudo yum install yum-utils

Now press y and then press <Enter> to continue.

yum-utils should be installed.

Now add the IUS package repository with the following command:

$ sudo yum install https://centos7.iuscommunity.org/ius-release.rpm

Now press y and then press <Enter> to continue.

IUS package repository should be added.

Now update the yum package repository cache again with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Now you’re ready to install Python 3.x.

Installing Python 3.4 and PIP for Python 3.4:

Only Python 3.4:

If you want to install only Python 3.4, not PIP for Python 3.4, run the following command:

$ sudo yum install python34u

Press y and then press <Enter> to continue.

You may be asked to accept the GPG key, press y and then press <Enter> to continue.

Python 3.4 should be installed.

Python 3.4 Including PIP for Python 3.4:

If you want to install Python 3.4 and PIP for Python 3.4, run the following command:

$ sudo yum install python34u python34u-pip

Now press y and then press <Enter> to continue.

Now press y and then press <Enter> to continue.

Python 3.4 and PIP for Python 3.4 should be installed.

Now you can check whether Python 3.4 is installed correctly with the following command:

$ python3.4 -V

As you can see, it is installed and working correctly.

You can also check whether PIP for Python 3.4 is installed correctly with the following command:

$ pip3.4 -V

As you can see, it works.

Installing Python 3.5 and PIP for Python 3.5

Only Python 3.5:

You can install only Python 3.5 and leave PIP for Python 3.5 with the following command:

$ sudo yum install python35u

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.5 should be installed.

Python 3.5 Including PIP for Python 3.5:

If you want to install Python 3.5 and PIP for Python 3.5, run the following command:

$ sudo yum install python35u python35u-pip

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.5 should be installed along with PIP for Python 3.5.

To test whether Python 3.5 works, run the following command:

$ python3.5 -V

To test whether PIP for Python 3.5 works, run the following command:

$ pip3.5 -V

Installing Python 3.6 and PIP for Python 3.6

Only Python 3.6:

You can install only Python 3.6 and leave PIP for Python 3.6 with the following command:

$ sudo yum install python36u

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.6 should be installed.

Python 3.6 Including PIP for Python 3.6:

If you want to install Python 3.6 and PIP for Python 3.6, run the following command:

$ sudo yum install python36u python36u-pip

Now follow the steps of the Installing Python 3.4 and PIP for Python 3.4 section of the article above. Python 3.6 should be installed along with PIP for Python 3.6.

To test whether Python 3.6 works, run the following command:

$ python3.6 -V

To test whether PIP for Python 3.6 works, run the following command:

$ pip3.6 -V

Changing Python Version on the Fly

You can access Python 3 using python3 command.

The default version of Python 3.x used for python3 command is Python 3.4.x.

If you have multiple version of Python 3 installed, you can change it as follows:

$ alias python3=$(which python3.x

NOTE: Here x = 4, 5, or 6 for Python 3.4, Python 3.5, and Python 3.6 respectively.

Now python3 is set to use Python 3.6.x as you can see from the screenshot below.

$ python3 -V

That’s how you install Python 3 on CentOS 7. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.