Overview

Those of you who are used to using CentOS should have the feeling that even the latest CentOS 7.8 comes with a version of Python that is still Python 2.7, for a number of complicated reasons, but in any case, this is more or less inconvenient for us to use on a regular basis. The requirement is that it must be Python 3.5 or higher, which is a bummer.

Here, I’m going to install the latest version of Python3 under my CentOS, which is currently Python3.8, so I decided to install that one, but, it should be noted that I’m not going to overwrite the original Python2.7, which means that eventually, on my system, there will be two Python versions that don’t interfere with each other, and if you feel that this hinders your use of them in some way, I’ve written a few articles before that can help you with these issues.

Download Python 3.8 source code

Python provides an FTP address, where you can download various versions of Python source code.

I downloaded the Python 3.8 version: Python-3.8.0.tgz.

[[email protected]]# wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz -O /tmp/Python-3.8.0.tgz
[[email protected]]# cd /tmp && tar zxf Python-3.8.0.tgz
[[email protected]]# cd python-3.8.0

Prepare for compilation

Since compiling Python source code depends on a lot of tools, you’ll need to prepare.

[[email protected]]# yum update -y
[[email protected]]# yum groupinstall -y 'Development Tools'
[[email protected]]# yum install -y gcc openssl-devel bzip2-devel libffi-devel

Compile and install Python 3.8

[[email protected]]# . /configure prefix=/usr/local/python3 --enable-optimizations
[[email protected]]# make && make install
[[email protected]]# export PATH=$PATH:/usr/local/python3/bin/

Test the installation.

To test that it installs correctly and works with Python 3.8 and pip3, I’ll use Virtualenv to verify that.

[[email protected]] curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
[[email protected]] python3.8 get-pip.py
[[email protected]] python3 -m pip install virtualenv
[[email protected]] python3 -m virtualenv venv
[[email protected]] source venv/bin/activate
(venv) [[email protected]] python --version
Python 3.8.0

OK, now everything is installed properly and Python3 can be used like any other environment.

Ref