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
sudo yum groupinstall "Development Tools" -ysudo yum install openssl11-devel libffi-devel bzip2-devel xz-devel -y- for static linking use
openssl11-static
- for static linking use
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:
./configure --enable-optimizations --with-lto --with-openssl=/opt/openssl111/ltois link time optimization
make -j8make altinstall(installs in/usr/local/not to overwrite system python)
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.
Is there any alternative way to install python 3.9 in Centos 7 instead of using source code (tar.gz/tgz)
Trying to install python3.9 on CentOS 7
How to install Python pip on CentOS 7?
How to change Python 2 to Python 3 on CentOS 7?
Videos
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
sudo yum groupinstall "Development Tools" -ysudo yum install openssl11-devel libffi-devel bzip2-devel xz-devel -y- for static linking use
openssl11-static
- for static linking use
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:
./configure --enable-optimizations --with-lto --with-openssl=/opt/openssl111/ltois link time optimization
make -j8make altinstall(installs in/usr/local/not to overwrite system python)
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. :-)