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 · Note: Using make altinstall prevents Python 3.9 from ...
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
Did it get installed but is now giving you this warning? 2021-01-04T04:51:12.5Z+00:00 ... Your make is probably still giving errors. Can you check the logs? 2021-01-04T05:01:36.887Z+00:00 ... Save this answer. ... Show activity on this post. CentOS 7, Python3.9, OpenSSL1.1.1k (Packages Used) More on stackoverflow.com
🌐 stackoverflow.com
Cleanest way to install Python 3.7 on CentOS 7 image
Have you considered usinh the official Python 3.7 Docker image ? More on reddit.com
🌐 r/docker
7
1
July 10, 2019
Trying to install python3.9 on CentOS 7
Just curious, why are you sticking with CentOS 7 instead of upgrading to CentOS Stream 9, Rocky Linux 9, RedHat EL 9 or Alma 9? More on reddit.com
🌐 r/CentOS
7
10
October 19, 2022
🌐
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
🌐
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.
🌐
Amosplanet
amosplanet.org › install-python-3-9-9-on-centos7
Install Python 3.9.9 on Centos7 – amosplanet
tar -zxvf Python-3.9.9.tgz cd Python-3.9.9 ./configure make&&make install · mv /usr/bin/python /usr/bin/python.bak #删除以前python2.7的软连接 ln -s /usr/local/bin/python3 /usr/bin/python mv /usr/bin/pip /usr/bin/pip.bak (如果报错说没有pip直接跳过) 以下为没有此文件或目录报错 · ln -s /usr/local/bin/pip3 /usr/bin/pip · python exit() pip -V · Installation Env.: Centos7 ·
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. :-)

Find elsewhere
🌐
Liquid Web
liquidweb.com › home › how to install python 3 on centos 7
Install Python 3 on CentOS 7: Easy Steps for Linux Users | Liquid Web
April 7, 2025 - Upgrade your CentOS 7 server to Python 3 with ease using our step-by-step guide featuring Yum and install Python3 Linux instructions.
🌐
Juejin
juejin.cn › 稀土掘金 › 开发工具 › 文章
Install Python 3.9 on CentOS 8 / CentOS 7In today’s guide yo - 掘金
September 1, 2022 - Run below command to confirm successful installation of Python 3.9 on CentOS 8 / CentOS 7: ... $ /usr/local/bin/python3.9 -m pip install --upgrade pip Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (22.0.4) Collecting ...
🌐
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,...
🌐
Workaround
workaround.cz › home › how to build, compile, and install the latest python 3.11, 3.10, 3.9, 3.8, and 3.7 on linux centos 7, 8, and 9
Howto build, install, compile latest Python 3.11, 3.10, 3.9, 3.8, 3.7 on Linux CentOS
October 26, 2022 - I have for you a short tutorial on how to build, compile and install Python 3.11, 3.10, 3.9, 3.8 or 3.7 on Linux CentOS 7 , 8 or 9 and run it without destroying the shipped Python in Centos.
🌐
Geekflare
geekflare.com › development › how to install python on mac: guide for seamless installation
How to Install Python 3 on CentOS, Ubuntu and Windows?
December 28, 2024 - Click the Install button. On the License Agreement page, click Agree. You should see the “Downloading software” dialog. Allow the process to complete itself. Once the process is over, run the command “python3 –version” again on the Terminal app and it should show the installed Python distribution version.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7
How To Install Python 3 and Set Up a Local Programming Environment on CentOS 7 | DigitalOcean
April 20, 2017 - This tutorial will guide you through installing Python 3 on your local CentOS 7 machine and setting up a programming environment via the command line. Python…
🌐
Thelinuxterminal
thelinuxterminal.com › how-to-install-python3-9-on-centos8
How to Install Python 3 On Centos/RHEL 8
June 7, 2021 - 4bits$ sudo /usr/local/bin/python3.9 -m project1 /home/4bits/python-app/project1 · Now once your environment has been created you need to activate the environment so that it can manage its own dependencies within that folder · 4bits$ source /home/4bits/python-app/project1/bin/activate · Now once you finish your task you can't activate the environment ... In this tutorial we have seen how you can install python3 specifically on centos 8 or RHEL based Operating system .