Install Python 3.7+ on CentOS 7

Step 1: Install requirements

# yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel xz-devel

Step 2: Download python

# cd /usr/src
# wget https://www.python.org/ftp/python/3.7.15/Python-3.7.15.tgz

Feel free to replace -3.7.15 by any version available

Step 3: Configuring and installing

# tar -xzf Python-3.7.15.tgz
# cd Python-3.7.15
# ./configure --enable-optimizations --enable-shared
# make altinstall

–enable-shared installs shared libraries instead of building into python. This enables some 3rd party modules to install and load (e.g. mod_wsgi)
make altinstall installs python as an alternative to the OS version, thus leaving the installed version untouched

Step 4: Post installation

To activate python on your system, add the path to /etc/ld.so.conf and run ldconfig (only needed the first time):

# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig

or simply run this commnand (this does not survive ldconfig reloads or system reboots):

# ldconfig /usr/local/lib