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
🌐
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 - sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel · Once that is done, navigate to the /usr/local/src directory: ... Congratulations, you have successfully installed Python 3.9 and PIP!
🌐
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.

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
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
People also ask

How to install Python pip on CentOS 7?
Install `pip` for Python 3: `sudo yum install python3-pip`
🌐
monovm.com
monovm.com › blog › centos › how to install python 3 on centos 7?
How to Install Python 3 on CentOS 7?
How to change Python 2 to Python 3 on CentOS 7?
CentOS 7 typically has Python 2 as the default. To use Python 3, explicitly call `python3` instead of `python` for commands, or consider adjusting symbolic links. Use `sudo alternatives --config python` to change the default Python version if alternatives are installed.
🌐
monovm.com
monovm.com › blog › centos › how to install python 3 on centos 7?
How to Install Python 3 on CentOS 7?
🌐
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
🌐
TecAdmin
tecadmin.net › install-python-3-9-on-centos
How to Install Python 3.9 on CentOS/RHEL 7 & Fedora – TecAdmin
April 26, 2025 - This Python installation required the GCC compiler on your system. Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it. sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
🌐
MonoVM
monovm.com › blog › centos › how to install python 3 on centos 7?
How to Install Python 3 on CentOS 7?
January 15, 2024 - Continue reading as we demystify ... you may need to Install Python CentOS 7. You have two basic options including Yum install Python 3.8 CentOS 7....
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
🌐
Eldernode
blog.eldernode.com › linux vps › install python 3.9 on centos 8 & centos 7
How To Install Python 3.9 On CentOS 8 & Centos 7
November 8, 2020 - python does not install in centos by default. for this reason, in this article we will teach you how to install python 3.9 on centos 8, centos 7
🌐
Amosplanet
amosplanet.org › install-python-3-9-9-on-centos7
Install Python 3.9.9 on Centos7 – amosplanet
yum install wget · 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 ·
🌐
Vinod Pandey
vinodpandey.com › how-to-install-python3-on-centos-7
How to Install Python 3 on Centos 7 | Vinod Pandey
January 10, 2021 - Introduction In this tutorial we will install Python 3.6, 3.7, 3.8 & 3.9 on CentOS 7. The default python version in CentOS 7 is 2.7.5. If we forcefully upgrade or replace this version, yum and other utitiles may break causing the OS to become unstable.
🌐
Gcptutorials
gcptutorials.com › post › how-to-install-python3.9-on-centos
How to install Python3.9 on CentOS - gcptutorials
Master Biology, Chemistry, Physics, and English with interactive MCQs, calculators, tools, and worksheets. Free resources for students and exam preparation.
🌐
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).
🌐
Serverspace
serverspace.io › support › help › install-python-centos
How to Install or Upgrade Python on CentOS 7/8 Stream: Build the Latest Python from Source
February 16, 2026 - If version 3.11.x of Python is displayed, then all previous steps have gone correctly! It is now possible to use the universal programming language for your own purposes. If you already have an earlier version of Python, follow the steps below. In order to perform a Python version upgrade, a few new packages must be supplied in addition. Send commands to the terminal: yum groupinstall -y "Development Tools" --skip-broken
🌐
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.
🌐
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 - In order to install Python 3 from source, we are going to need to ensure that some prerequisite packages are installed on our system. [root@centos7 ~]# yum install gcc openssl-devel bzip2-devel libffi-devel -y
🌐
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 - 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):
🌐
DevOpsSchool.com
devopsschool.com › blog › installing-python-3-on-linux-centos-ubuntu-windows
Python Tutorials: Installing Python 3 on Linux, Centos, Ubuntu & Windows
sudo yum -y install wget make gcc openssl-devel bzip2-devel cd /tmp/ wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz tar xzf Python-3.7.9.tgz cd Python-3.7.9 ./configure --enable-optimizations sudo make altinstall sudo ln -sfn ...
🌐
Medium
rakeshjain-devops.medium.com › how-to-install-python-3-on-centos-7-7-using-yum-and-source-and-set-as-default-1dee13396f7
How to Install Python 3 on CentOS 7.7 using yum/source and set as Default | by Rakesh Jain | Medium
October 13, 2020 - [root@centos7 ~]# yum install ftp File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax · To fix this change the python interpreter to `/usr/bin/python2.7` in two files
🌐
Unihost
unihost.com › help › how to install python 3
How to Install Python 3 - Unihost.FAQ
February 23, 2023 - This guide will walk you through how to install the most recent version of Python 3 on CentOS 7 and Ubuntu 18.04 or Ubuntu 20.04. Before you begin, refresh the package listings. This helps ensure that yum is up to date.
🌐
Linux Stans
linuxstans.com › how-to-install-python-centos
How to Install Python 3.10 (or 3.11) on CentOS - Linux Stans
January 24, 2022 - Python 3.9.6 is the latest version available in the CentOS 8 repos. The EOL of Python 3.9.6 is Oct 2025, so you can use that version. To install it, just run yum install python39 and that’s it.