How to Install Python 3 on Centos 7

Introduction

In this tutorial we will install Python 3.6, 3.7, 3.8 & 3.9 on CentOS 7. The default python version in CentOS 7 is 2.7.5. If we forcefully upgrade or replace this version, yum and other utitiles may break causing the OS to become unstable.

Instead of upgrading/replacing default python, we will install the new version of python using alternate install method. This setup will also install corresponding pip for each python version separately.

Installing Python 3.6 on CentOS 7

Step 1: System Package Installation

Install below pre-requisites:

1
sudo yum -y install wget make gcc openssl-devel bzip2-devel

Step 2: Downloading Python 3.6

Download python setup in tmp location

1
2
cd /tmp/
wget https://www.python.org/ftp/python/3.6.12/Python-3.6.12.tgz

Step 3: Python 3.6 alternate installation

1
2
3
4
5
6
7
8
tar xzf Python-3.6.12.tgz
cd Python-3.6.12
./configure --enable-optimizations
sudo make altinstall

sudo ln -sfn /usr/local/bin/python3.6 /usr/bin/python3.6
sudo ln -sfn /usr/local/bin/pip3.6 /usr/bin/pip3.6

Step 4: Verifying new python and pip version

1
2
3
4
5
6
7

python3.6 -V
Python 3.6.12

pip3.6 -V
pip 18.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

Installing Python 3.7 on CentOS 7

Step 1: System Package Installation

Install below pre-requisites:

1
sudo yum -y install wget make gcc openssl-devel bzip2-devel

Step 2: Downloading Python 3.7

Download python setup in tmp location

1
2
cd /tmp/
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz

Step 3: Python 3.7 alternate installation

1
2
3
4
5
6
7
tar xzf Python-3.7.9.tgz
cd Python-3.7.9
./configure --enable-optimizations
sudo make altinstall

sudo ln -sfn /usr/local/bin/python3.7 /usr/bin/python3.7
sudo ln -sfn /usr/local/bin/pip3.7 /usr/bin/pip3.7

Step 4: Verifying new python & pip version

1
2
3
4
5
python3.7 -V
Python 3.7.9

pip3.7 -V
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

Installing Python 3.8 on CentOS 7

Step 1: System Package Installation

Install below pre-requisites:

1
sudo yum -y install wget make gcc openssl-devel bzip2-devel

Step 2: Downloading Python 3.8

Download python setup in tmp location

1
2
cd /tmp/
wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tgz

Step 3: Python 3.8 alternate installation

1
2
3
4
5
6
7
8
tar xzf Python-3.8.7.tgz
cd Python-3.8.7
./configure --enable-optimizations
sudo make altinstall

sudo ln -sfn /usr/local/bin/python3.8 /usr/bin/python3.8
sudo ln -sfn /usr/local/bin/pip3.8 /usr/bin/pip3.8

Step 4: Verifying new python & pip version

1
2
3
4
5
python3.8 -V
Python 3.8.7

pip3.8 -V
pip 20.2.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

Installing Python 3.9 on CentOS 7

Step 1: System Package Installation

Install below pre-requisites:

1
sudo yum -y install wget make gcc openssl-devel bzip2-devel

Step 2: Downloading Python 3.9

Download python setup in tmp location

1
2
cd /tmp/
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz

Step 3: Python 3.9 alternate installation

1
2
3
4
5
6
7
8
tar xzf Python-3.9.1.tgz
cd Python-3.9.1
./configure --enable-optimizations
sudo make altinstall

sudo ln -sfn /usr/local/bin/python3.9 /usr/bin/python3.9
sudo ln -sfn /usr/local/bin/pip3.9 /usr/bin/pip3.9

Step 4: Verifying new python & pip version

python3.9 -V
Python 3.9.1

pip3.9 -V
pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9