The default setting in the system centos 7 is the installed version of Python 2.7. Below I will explain how to install CentOS 7 server with a more recent version of Python 3. In fact, it was not such a simple task as it may seem.

Introduction

In General, installing python 3 on CentOS 7 is no big deal, but nevertheless, it doesn’t do the usual install package from the standard repository, or epel. More precisely, it is possible to set, but by default will run the old version.

Or, for example, you might want to have 2 or more versions of Python in the system and then promptly switch to run scripts with the different version. In General, there are small nuances, but all in good time.

Installing Python 3.6 on Centos 7

If you just have to put a naked version of Python, for example, of 3.6, at the time of writing it is in the epel repository. You need to first add 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 version of Python in the console:

# python -V
Python 2.7.5

Will see that by default is called the old version. If you want to start new, you have to run 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 to /usr/bin/python36. But if someone needs an older version, the problems begin. For example, will stop working yum, This situation can be handled in different ways. One of them I will describe in the next section, where we will show you how to install several different python versions and work with them.

I always see recommendations, instead of the epel repository, to use ius to install python. At least, because there immediately, you can install the pip need version. I’ll talk about this below too. For example, in epel there is python36, but not to him pip36 only 3.4. It’s uncomfortable. So we include the ius repository and put all the necessary.

# yum install https://centos7.iuscommunity.org/ius-release.rpm
# yum install python36u python36u-devel python36u-pip

Check:

# python3.6 -V
Python 3.6.5

Installing multiple versions of Python

What to do to make it comfortable to work with different versions of Python? You can set the repository so-called Software Collections or SLC and put a version of Python from there. Its convenience is that there is a tool that will allow you to run bash shell with the new version of Python to run the scripts, which need this version and just exit the shell. I just helped this way when you need to quickly execute one-time scripts that need was version 3 and that did test this version through the appeal to the system python.

Connect the SCL repository:

# yum install centos-release-scl

Set the desired Python version, such as 3.6.

# yum install rh-python36

You can now do this:

# scl enable rh-python36 bash

And we are in the console with the correct version of Python.

# python -V
Python 3.6.3

You can run scripts that require this version. They when you start make sure that the version is the one that is needed.

Installation Manager pip and python packages

At the same time will show you how to install the package manager pip correct version and packages to him. As already mentioned above, you need to connect the ius repository, if not connected previously, and complete the installation.

# yum install https://centos7.iuscommunity.org/ius-release.rpm
# yum install python36u-pip

You can immediately after installation to upgrade pip to the latest version:

# pip3.6 install --upgrade pip

For example, let’s install the Python module via pip jpath.

# pip3.6 install jpath

jpath

Shares:
Show Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

11 − 7 =