If you want to understand in more detail the processes of setting up and providing comprehensive security for the local and network infrastructure, built on the basis of the Linux OS, I recommend that you get acquainted with Linux Security Online Course in OTUS. The course is not for beginners, for admission you need to go.
In general, there is nothing complicated about installing python 3 on CentOS 7, but you can’t do this by simply installing the package from a standard repository or epel. More precisely, you can install, but the old version will work by default.
Or, for example, you may need to have 2 or more versions of python in the system and somehow quickly switch to run scripts with different versions. In general, there are small nuances, but first things first.
Install Python 3.6 on Centos 7
If you just need to install the bare Python version, for example, 3.6, then at the time of writing this article is in the epel repository. You need to first connect the repository, and then install the new version.
# yum install epel-release # yum install python36
And that’s all. But if after that, you check the python version in the console:
# python -V Python 2.7.5
See that the old version is called by default. If you want to launch exactly the new one, then you need to launch exactly version 3.6.
# python36 -V Python 3.6.3
You can replace the standard version by changing the symbolic link python with / usr / bin / python2 on / usr / bin / python36. But if someone needs the old version, problems will begin. For example, yum will stop working 🙂 This situation can be resolved in various ways. I will describe one of them in the next section, where I will show how to install several different versions of python and work with them.
I see recommendations everywhere, instead of the epel repository, use ius to install python. At a minimum, because there you can immediately install pip you need the version. I will talk about this below too. For example, in epel there is python36, but there is no pip36 to it, only 3.4. It is not comfortable. So we connect the ius repository and put everything we need.
# yum install https://centos7.iuscommunity.org/ius-release.rpm # yum install python36u python36u-devel python36u-pip
# python3.6 -V Python 3.6.5
Install multiple versions of Python
What to do to work conveniently with different versions of python? You can install the so-called repository Software Collections or SLC and put the python version from there. Its convenience will be that there is a tool that will allow you to run a bash shell with a new version of python, execute scripts that need this version and just exit the shell. This method just helped me when I needed to quickly execute one-time several scripts that needed version 3 and which did the verification of this version by accessing the system python.
Connect the SCL repository:
# yum install centos-release-scl
We put Python of the necessary version, for example 3.6.
# yum install rh-python36
Now you can do this:
# scl enable rh-python36 bash
And we find ourselves in the console with the correct version of python.
# python -V Python 3.6.3
You can run scripts that require this particular version. They will make sure at startup that the version is exactly what they need.
Install pip manager and python packages
At the same time, I will show how to install the pip package manager of the desired version and packages to it. As mentioned above, you need to connect the ius repository, if you have not connected it before and complete the installation.
# yum install https://centos7.iuscommunity.org/ius-release.rpm # yum install python36u-pip
You can update pip to the latest version immediately after installation:
# pip3.6 install --upgrade pip
For example, install the jpath python module via pip.
# pip3.6 install jpath