Firstly, install the requsite packages.
sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
Once that is done, download python3.9 or newer version.
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
Extract it.
tar -xvf Python-3.9.6.tgz
Move into the directory and configure with following command.
./configure
I am not using the “–enable-optimizations” option because centos7 countered compilation error below.
SystemError: <built-in function compile> returned NULL without setting an error generate-posix-vars failed.
This problem can be solved by updating gcc to the last version.
After running the configure command, execute the following
sudo make
sudo make altinstall
Now, we can check the version


Ok, that’s it!