By default, CentOS 7 comes with Python 2.7.5 preinstalled, meaning that if you will need Python 3 for whatever reason, you will need to install it by setting up a third party repository and then install it manualy.

Install the needed utilities

Only adding the repository is not enough, thus you will need to create a working programming environment on your system, therefore you will need to have some utilities for software build and compilation, thus you will install the developement group of packages.

Before we go further, lets find out what group packages are? Well, the group packages are nothing more than a group of software packages that are kept organized into specific group names. In order to find out what kind of group packages your CentOS system is offering you can issue the command:

sudo yum group list

In my case, the output is as follows:

Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Cinnamon Desktop
   MATE Desktop
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   CIFS file server
   Compatibility Libraries
   Console Internet Tools
   Desktop Platform
   Desktop Platform Development
   Development Tools
   Educational Software
   Electronic Lab
   FCoE Storage Client
   Fedora Packager
   General Purpose Desktop
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Messaging Client Support
   Messaging Server Support
   MySQL Database client
   MySQL Database server
   NFS file server
   Network Storage Server
   SNMP Support
   Scientific Support
   Security Tools
   Server Platform
   Server Platform Development
   Smart Card Support
   Storage Availability Tools
   System Administration Tools
   System Management
   TeX support
   TurboGears application framework
   Web-Based Enterprise Management
   iSCSI Storage Client

As you may notice, the ones listed under Available Environment Groups are the ones available in the Anaconda Installer, and provide specific packages for any type of Environment that you might want to use. In the Available Groups listing are all the software packages available for specific “tasks” like system management, virtualization, graphical administration tools - just to name a few. In our case, we will need the Development Tools group of packages. You might also need the Desktop Platform Development group or the Server Platform Development if you need more specific tools for certain desktop or server related tasks.

Now let us proceed and install yum-utils (a collection of plugins for yum) and then the group packages for development.

sudo yum update
sudo yum install yum-utils
sudo yum groupinstall Development Tools

Install third-party repository

In order to install the latest version of Python in your CentOS 7, you will need to add a new repository, called IUS. To do this, issue the following command:

sudo yum -y install

then do a system update with the command:

sudo yum update

Install Python 3

The latest version, as of the time of this writing, was 3.6.4 released on the 19th of December 2017, and versions 3.5.5 and 3.4.8 available starting February 4th 2018. You can check and download them from here.

To install Python 3.6.x issue the command:

sudo yum install python36u

This will install Python version 3.6.4, the latest available. You can check for the version number of the package installed, using the command:

python3.6 -V

If you run the command

python -V

you will get a different answer, and you will see that the version shown by the system is 2.7.5, the default one installed by CentOS 7. This means that both versions are installed on your system.

Install Python libraries

After you install Python 3, you will need to install some Python libraries, needed for development. For this, we need the python36u-devel package. Also, we will install pip the utilitary that you will use to install specific python packages.

sudo yum install python36u-libs
sudo yum install python36u-devel
sudo yum install python36u-pip

You can also install the python36u-tools and tk-devel packages:

sudo yum install python36u-tools
sudo yum install tk-devel

That’s it. Now you have Python3 installed on your CentOS 7, alongside Python 2.7. Enjoy and happy coding!