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.

[root@liqiang.io]# wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz -O /tmp/Python-3.8.0.tgz
[root@liqiang.io]# cd /tmp && tar zxf Python-3.8.0.tgz
[root@liqiang.io]# cd python-3.8.0

Prepare for compilation

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

[root@liqiang.io]# yum update -y
[root@liqiang.io]# yum groupinstall -y 'Development Tools'
[root@liqiang.io]# yum install -y gcc openssl-devel bzip2-devel libffi-devel

Compile and install Python 3.8

[root@liqiang.io]# . /configure prefix=/usr/local/python3 --enable-optimizations
[root@liqiang.io]# make && make install
[root@liqiang.io]# 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.

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

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