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:
In my case, the output is as follows:
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.
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:
then do a system update with the command:
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:
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:
If you run the command
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.
You can also install the
That’s it. Now you have Python3 installed on your CentOS 7, alongside Python 2.7. Enjoy and happy coding!