When we need to work on Python scrips in Linux machine, we work on python2.7, as it is installed default on most of Linux distributions. So what if we need to work on python3 and that is not installed on our Linux machine like latest CentOS7. In these case, we need to install pyhton3 on your machine.So In this post we would see HowTo Install Python 3 and Set Up a Local Programming Environment on CentOS 7.

Python is widely used in all types of industries from over couple of decades and python3 new and enhance version of python which would future of Python and would widely accepted around world, so it would good opportunity to work on it and understand its bare concepts and advantages over earlier version. There is only way to safely practice it with old version that support your machine that we create virtual setup for new python3.

For this setup we are using latest CentOS7 as of now Nov 2017.

[root@centos7-box ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

[root@centos7-box ~]# uname  -rm
3.10.0-693.5.2.el7.x86_64 x86_64

Prepare System

Before we start installing Python3, we should update our machine and install Development Tools which would help build and compile software source. So we need to install them like mentioned below.

# yum -y install yum-utils 
# yum -y groupinstall development

Installing Python 3

Now we are ready to install python3 on CentOS7. As we all know CentoS is Redhat distribution Linux project which is same as RHEL operating system and try to be as stable as could, that’s why its is always have stable packages in its repository. So because of this python3 is not included in CentOS official repository, But there is another most current upstream stable (IUS) repository. We could latest stable python, python development and pip packages with this repository, like mentioned below.

# yum -y install https://centos7.iuscommunity.org/ius-release

Now we could install python3

# yum -y install python36u python36u-devel python36u-pip

After installation we could verify installation like below.

# python3.6 -V
Python 3.6.3

We can install Python packages with pip like below, pip is good way manage python packages used for python development.

# pip3.6 install bottle hypothesis mypy pyflakes

Creating Virtual Environment

Now Python3 has been installed on system, we can create programming environment through venv. Virtual environment provide separate isolate space for your project. We can create as many as python development environment for projects as we work on them. Below we are creating one project which used to fetch data from different random websites.

Create a directory for python projects
[root@centos7-box ~]# mkdir /python_vm
[root@centos7-box ~]# cd /python_vm/

Create python module with directory web_collector
[root@centos7-box python_vm]# python3.6 -m venv web_collector
[root@centos7-box python_vm]# ls
[root@centos7-box web_collector]# ls web_collector
bin  include  lib  lib64  pyvenv.cfg

start web_collector environment
[root@centos7-box python_vm]# source web_collector/bin/activate
(web_collector) [root@centos7-box python_vm]#