How to Install Python3 on Centos7?

Venu Madhav
3 min readJun 13, 2020

--

In this article we will learn how to install python3 on Linux Centos7. By default, Centos7 comes up with python 2.7.5. Also, python3 is not available in the official package repo of Cento7.

python2 supports end in 2020. So, one must switch to python3.

We will install python3 through Software Collections(SCL) which gives us the power to build and concurrently install multiple versions of the same package on our system, without affecting the system default packages installed from our distribution.

We are not removing or upgrading the existing python version which was 2.7.5 which was default package shipped with centos7. With the help of SCL, we are installing the python3 alongside with existing python2.7.5.

Below are the steps to install python3 through SCL.

  1. Install the SCL repo by executing the below command.
sudo yum install centos-release-scl

2. Find the python version which we are interested in. We can browse the list of python versions available under SCL repo.

3. In this article we will install the python 3.6 version using the below command.

sudo yum install rh-python36

4. Next, run the below command which enables us to access the latest python3.6 version. This will launch a new shell instance.

scl enable rh-python36 bash

5. Verify the python version in the same shell, by using the below command, which outputs the 3.6 version.

python --version

6. If you exit the shell and check for python version, we can see python version as 2.7.5. This means, the python3 is enabled only when we enable the python36 shell by entering the above command which is “scl enable rh-python36 bash”.

Successfully we have installed the python3 version alongside, without disturbing the existing default installed package which is python2.7.5.

Now, we can work in any environment. Just enable the “rh-python36 bash” to use the python3 environment in the terminal.

Now, we will see how to create Virtual Environment to launch in pycharm IDE.

Virtual Environment is used to keep the dependencies required by different projects, separated by creating a isolated python virtual environments for them.

Virtual environment is created by using the “venv” command

Lets say, we want to create a python3 project with matching virtual environment.

create a directory and navigate to that directory.

mkdir my_new_project
cd my_new_project

Enable the python3 using the SCL tool, by using the below command

scl enable rh-python36 bash

Execute the below command, to create virtual environment named my_project_venv.

python -m venv my_project_venv

Activate the above created virtual environment by executing the below command.

source my_project_venv/bin/activate

After executing the above command, the shell will prefix with name of the virtual environment as shown below.

(my_project_venv) [venram@centos7 my_new_project]$

Install the pycharm on centos 7. Refer to Installation procedure on centos7.

Now, browse to the pycharm directory and navigate to bin folder and launch the pycharm IDE by running pycharm.sh file.

After launching the pycharm IDE, click on ‘OPEN’ and navigate to the above created directory were we have created the virtual environment which is “my_new_project”.

All set, we have successfully launched the project with python3 version. We can verify python3 modules by expanding the directory structure of ‘my_project_venv’.

Conclusion:

We have installed python3 alongside with existing default python 2.7.5 version in centos7 machine.

Now, we can develop python3 projects in centos7 machine without being disturbing the default python version.

Please check on Installation of pycharm IDE in centos7 machine.

REFERENCE:

--

--