Python3.10 source build on CentOS 7.6

The above posts were very helpful to guide me to my solution. I want to share in case someone else could use this:

First the development libs

  1. sudo yum groupinstall "Development Tools" -y
  2. sudo yum install openssl11-devel libffi-devel bzip2-devel xz-devel -y
    • for static linking use openssl11-static

Then configure

So for some reason CentOS ships openssl1.1.1 but it is installed in a way that doesn't jive with Python's configure script.

# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
    # an 'openssl' subdirectory

    if ! $found; then
        OPENSSL_INCLUDES=
        for ssldir in $ssldirs; do
            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5
$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; }
            if test -f "$ssldir/include/openssl/ssl.h"; then
                OPENSSL_INCLUDES="-I$ssldir/include"
                OPENSSL_LDFLAGS="-L$ssldir/lib"
                OPENSSL_LIBS="-lssl -lcrypto"

Since Python is including headers a subfolder is desired: $ssldir/include/openssl/ssl.h

I just created a new folder with the correct layout:

/opt/openssl111/
├── include
│   └── openssl
│       └── *.h
└── lib
    ├── libcrypto.so
    └── libssl.so

Once in place, the trifecta:

  1. ./configure --enable-optimizations --with-lto --with-openssl=/opt/openssl111/
    • lto is link time optimization
  2. make -j8
  3. make altinstall (installs in /usr/local/ not to overwrite system python)
Answer from squjd on Stack Overflow
🌐
Reddit
reddit.com › r/centos › trying to install python3.9 on centos 7
r/CentOS on Reddit: Trying to install python3.9 on CentOS 7
October 19, 2022 -

I've tried a few didnt online guides but nothing seems to be helping me achieve what I'm looking for. I have a Linux machine for my network environment that I use for automation. I'm trying to upgrade my python 3.6.8 to some version of 3.9.x. I want to remove python 3.6.8, install 3.9, and then put 3.9 as the default for every user on the box.

Current Version of Linux 3.10.0-1160.6.1.el7.x86_64

I'm not a linux pro but I know some things.

🌐
Medium
medium.com › @vivekpemawat › setting-up-python3-9-3f4373dccb92
Setting Up Python 3.9 on centos7: A Quick Guide - Vivek Pemawat - Medium
December 8, 2023 - sudo yum install wget wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz tar xzf Python-3.9.6.tgz cd Python-3.9.6 sudo ./configure --enable-optimizations sudo make altinstall
Discussions

Is there any alternative way to install python 3.9 in Centos 7 instead of using source code (tar.gz/tgz)
Is there any alternative way to install python 3.9 instead of using source code (tar.gz/tgz) More on discuss.python.org
🌐 discuss.python.org
9
0
January 19, 2023
On CentOS, how do I build Python 3.9 from source while incorporating my openssl module? - Stack Overflow
This method works for installing Python 3.9 (from source) while incorporating the OpenSSL socket module. OpenSSL package also installed from source (away from base OS / yum package install locations). Summary: All packages directed to install in /usr/local/ Install Developments Tools for base OS (CentOS 7... More on stackoverflow.com
🌐 stackoverflow.com
Problem installing Python 3.9 RPM with yum on Centos 7
Is there a reason why you didn't start with the python3 SRPM in CentOS? More on reddit.com
🌐 r/linuxquestions
4
1
January 17, 2023
centos7 - Is there any way to install Python 3.9 on Centos 7 without using source code (tar.gz/tgz)? - Stack Overflow
Is there any alternative way to install Python 3.9 in Centos 7 instead of using source code (tar.gz/tgz)? We are running Python scripts so expecting Python to be installed at OS level and don’t wan... More on stackoverflow.com
🌐 stackoverflow.com
🌐
InMotion Hosting
inmotionhosting.com › inmotion hosting home › support › server technologies › linux › how to install python 3.9 on centos 7
How to Install Python 3.9 on CentOS 7 | InMotion Hosting
March 21, 2025 - Now that we have PIP installed, we can proceed with installing the latest version of Python, 3.9. Before installing Python you will first need to install the requisite software packages using the following command: sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
Top answer
1 of 7
6

Python3.10 source build on CentOS 7.6

The above posts were very helpful to guide me to my solution. I want to share in case someone else could use this:

First the development libs

  1. sudo yum groupinstall "Development Tools" -y
  2. sudo yum install openssl11-devel libffi-devel bzip2-devel xz-devel -y
    • for static linking use openssl11-static

Then configure

So for some reason CentOS ships openssl1.1.1 but it is installed in a way that doesn't jive with Python's configure script.

# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
    # an 'openssl' subdirectory

    if ! $found; then
        OPENSSL_INCLUDES=
        for ssldir in $ssldirs; do
            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5
$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; }
            if test -f "$ssldir/include/openssl/ssl.h"; then
                OPENSSL_INCLUDES="-I$ssldir/include"
                OPENSSL_LDFLAGS="-L$ssldir/lib"
                OPENSSL_LIBS="-lssl -lcrypto"

Since Python is including headers a subfolder is desired: $ssldir/include/openssl/ssl.h

I just created a new folder with the correct layout:

/opt/openssl111/
├── include
│   └── openssl
│       └── *.h
└── lib
    ├── libcrypto.so
    └── libssl.so

Once in place, the trifecta:

  1. ./configure --enable-optimizations --with-lto --with-openssl=/opt/openssl111/
    • lto is link time optimization
  2. make -j8
  3. make altinstall (installs in /usr/local/ not to overwrite system python)
2 of 7
6

When you compile Python, you need to tell it which OpenSSL headers and libraries to use.

First, install openssl11-devel:

sudo yum install --assumeyes openssl11-devel

Second, before running "./configure" set CFLAGS and LDFLAGS from the values emitted by pkg-config

export CFLAGS="$CFLAGS $(pkg-config --cflags openssl11)"
export LDFLAGS="$LDFLAGS $(pkg-config --libs openssl11)"

Third, configure and build as normal:

./configure --prefix=/some/where/dir
   # ... etc ...

This is the most reliable way to get the correct flags passed to the compiler and linker. It's also worth checking that there aren't any conflicting values being passed into the CFLAGS / LDFLAGS environment variables, which might stymie your efforts.

This assumes that you have the openssl-devel package installed, obviously. :-)

🌐
GitHub
gist.github.com › xcsrz › 15c3d2509db3aada0d7c16bfb5b95f33
Install Python 3.9 on CentOS or Amazon Linux · GitHub
Install Python 3.9 on CentOS or Amazon Linux · Raw · install-python-3.9-on-centos.sh · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
Centmin Mod
community.centminmod.com › threads › custom-python-3-7-3-8-3-9-3-10-rpm-builds-for-centos-7.22456
CentOS 7.x - Custom Python 3.7, 3.8, 3.9 & 3.10 RPM Builds For CentOS 7 | Centmin Mod Community Support Forums
February 5, 2022 - CentOS 7 by default uses Python 2.7 and has side by side install support up to Python 3.6 via YUM repository RPM packages. For Python 3.7 and higher,...
🌐
Victordomingos
no-title.victordomingos.com › articles › 2020 › install_python_centos_linux › index.html
How to install the current Python version on CentOS Linux 7 | The No Title® Tech Blog
April 26, 2020 - You find out which development package provides that dependency. You install it using a package manager (for CentOS 7, it’s yum, but for other versions or other Linux distributions it could be dnf, apt-get or even other package managers).
🌐
AlexHost
alexhost.com › home › faq › comprehensive guide to installing python 3 on centos 7
Comprehensive Guide to Installing Python 3 on CentOS 7
October 7, 2024 - Python 3 is not available in the default CentOS 7 repositories. To access it, enable the EPEL (Extra Packages for Enterprise Linux) repository: ... The EPEL repository contains additional packages, including Python 3, that are not found in standard CentOS repositories. With the EPEL repository enabled, choose your Python version: ... This command installs Python 3.6 along with `pip3`, the package manager for Python. If you require a newer version, such as Python 3.9, utilize Software Collections (SCL):
🌐
Reddit
reddit.com › r/linuxquestions › problem installing python 3.9 rpm with yum on centos 7
r/linuxquestions on Reddit: Problem installing Python 3.9 RPM with yum on Centos 7
January 17, 2023 -

... but not rpm. Which has left me stumped.

I built Python 3.9.16 from source, and then packaged that as an RPM (using Gradle ospackage library).

./configure
make
make altinstall DESTDIR=${PWD}/fakeroot

If I try to yum install on Centos 7.9, I get a whole load of errors relating to python(abi) and it ultimately refuses to install as there's a requirement to uninstall system Python 2.7.

But if I rpm -i the same file, it installs no problem.

Querying the RPM I built (rpm -qlvp) there are no references to /usr/bin/python.

Why's Yum finding blocking dependencies and rpm is not?

SOLVED: Error/ignorance on my part!

When creating the RPM package, the following fields must be set exactly so:

  • Name: python3

  • Release: n.el7 (where n can be incremented to force Yum to treat it as an upgrade version)

I had "python" and "1" respectively... which I suspect rpm ignores, but Yum uses to work out the dependency chain, and my values were too ambiguous.

Changing them to the values above allowed me to install via yum with no errors whatsoever (and completely unaffecting the system installation of Python).

🌐
Atlantic.Net
atlantic.net › home › blog › how to: installing python 3 and creating a virtual environment (venv) in centos 7
How to: Installing Python 3 and Creating a Virtual Environment (venv) in CentOS 7
June 4, 2024 - This article covers the installation of Python 3.9 on a CentOS 7 operating system and how to create a Virtual Environment(venv) with pyvenv for which Python 3 can run. It is essential to note the directories that we are installing is Python 3.9. CentOS 7.x is dependent on Python 2.x to function correctly, do not overwrite the Python 2 installation accidentally.
🌐
Liquid Web
liquidweb.com › home › how to install pip on centos 7
How to Install Pip on CentOS 7 | Liquid Web
November 20, 2024 - pip show pylint Name: pylint Version: 2.9.6 Summary: python code static checker Home-page: https://github.com/PyCQA/pylint Author: Python Code Quality Authority Author-email: [email protected] License: GPL-2.0-or-later Location: /opt/lib/python3.9/site-packages Requires: astroid, toml, mccabe, isort Required-by: spyder · In this guide, you’ve been shown how to install Pip on CentOS 7.
🌐
DedicatedCore
dedicatedcore.com › home › how to install latest version of python 3.10 on centos 7
How to Install Latest Version of Python 3.10 on CentOS 7 - DedicatedCore Blog
May 29, 2025 - You must manually put it up on CentOS 7 because it is not preloaded. Depending on the version you want, this guide walks you through two alternatives for installing Python 3 on CentOS 7. For those beginning their Python journey on Ubuntu. This complete tutorial on setting up your development environment offers step-by-step instructions.
Top answer
1 of 4
6

You can safely install Python as a Local / Non-root user by executing the below code with the required Python Version defined in the variable "PYTHON_VER"

Note: This installs Python in your $HOME directory. You can modify the PATH if needed for a different installation location.

# Install Python3 and Libraries as a local user. 
python_config() {
    export PYTHON_VER="3.12.4" 
    export PYTHON_VER_SHORT="$(echo ${PYTHON_VER} | cut -d '.' -f1,2)"
    export PYTHON_REQ="/tmp/requirements.txt"
    cd ~ 
    rm -rf ~/python && mkdir -p ~/python 
    echo "" >> ~/.bashrc 
    echo "export PATH=~/python/bin:$PATH" >> ~/.bashrc 
    source ~/.bashrc 
    wget --quiet --no-check-certificate "https://www.python.org/ftp/python/${PYTHON_VER}/Python-${PYTHON_VER}.tgz" 
    tar -zxvf ~/Python-${PYTHON_VER}.tgz 1>/dev/null 
    cd ~/Python-${PYTHON_VER}/ 
    echo "Python ${PYTHON_VER} - Installing in current logged-in user - $(whoami)" 
    echo "Python ${PYTHON_VER} - Installation in-progress. Please wait..." 
    ./configure --enable-optimizations --prefix=$HOME/python > /dev/null 2>&1; 
    echo "Python ${PYTHON_VER} - ETA: upto 5mins. Please wait..." 
    make altinstall > /dev/null 2>&1; 
    ln -s ~/python/bin/python${PYTHON_VER_SHORT} ~/python/bin/python3 
    ln -s ~/python/bin/pip${PYTHON_VER_SHORT} ~/python/bin/pip3 
     

    # Install PIP3
    wget --quiet --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python3 - --prefix=$HOME/python
    source ~/.bashrc
    ~/python/bin/pip3 install --upgrade pip 
    ~/python/bin/pip3 install --upgrade --no-cache-dir -r ${PYTHON_REQ} --use-pep517 
    cd ~ && rm -rf ~/Python-${PYTHON_VER}*


    ~/python/bin/python3 --version 
    ~/python/bin/pip3 --version 
    echo "Python ${PYTHON_VER} - Setup Completed!" 
}

# Function Call
python_config
2 of 4
2

Ubuntu 20.04 and later has the python3.9 package in its default repositories. It can be installed alongside the default python3.8 package with sudo apt update && sudo apt install python3.9 Installing the python3.9 package from the default Ubuntu repositories simplifies package management.

If you are using Ubuntu 20.04 keep Python 3.8 as the default Python 3.x version and switch to Python 3.9 only when necessary using update-alternatives. After you are done using Python 3.9 you can switch the it back to the default Python 3 version.

  • List installed versions of Python: update-alternatives --list python

  • Switch between Python versions: update-alternatives --config python

    From the terminal command-line Press <enter> to keep the current choice[*], or type selection number:

🌐
Stack Overflow
stackoverflow.com › questions › 75171790 › is-there-any-way-to-install-python-3-9-on-centos-7-without-using-source-code-ta
centos7 - Is there any way to install Python 3.9 on Centos 7 without using source code (tar.gz/tgz)? - Stack Overflow
Is there any alternative way to install Python 3.9 in Centos 7 instead of using source code (tar.gz/tgz)? We are running Python scripts so expecting Python to be installed at OS level and don’t wan...
🌐
Stack Exchange
unix.stackexchange.com › questions › 761552 › installing-python-3-9-on-rhel-7-using-ansible-2-9-27
Installing Python 3.9 on RHEL 7 Using Ansible 2.9.27 - Unix & Linux Stack Exchange
November 15, 2023 - I can try to create a playbook and add the steps from the above document to Ansible shell or command module, but my concern / question is - is it possible to instal Python 3.9 and install / upgrade Ansible to version 2.11 where currently my Ansible is 2.9.27 and Python is Python 2? Or is there a better way to automate these 2 installs / upgrades on all of confluent servers in the different environments? Can someone provide some guidance on this? Or am I stuck doing both of these manually ? ... This is what RHEL software collections is intended for, but RHEL 7 is really old - 3 years passed its "full support" period.
🌐
DEV Community
dev.to › hasone › installing-python3-alongside-the-default-python2-on-centos-rhel-4450
installing Python3 alongside the default python2 on CentOS (RHEL) - DEV Community
June 18, 2022 - [root@centos7 ~]# yum install gcc openssl-devel bzip2-devel libffi-devel -y · We'll be using Source installation as we want the latest version of python above 3.6 as the yum give us python3.6, look for the version you intended to install https://www.python.org/ftp/python/, in my case I'm gonna install 3.9 so here is the URL https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tgz.