I am attempting to install python 3.12.3 in a docker image based on centos7. I’ve researched how to do this, and it seems there is no redhat prebuilt rpm to install, so my only choice is to build from source. Following instructions on the web, I created this
Dockerfile:
FROM centos:7
# Set bash as the default shell
SHELL ["/bin/bash", "-c"]
RUN yum -y update
RUN yum install -y openssl-devel bzip2-devel libffi-devel zlib-devel gcc wget epel-release.noarch openssl11-devel
RUN yum groupinstall -y "Development Tools"
# RUN set -x
# localedef -i en_US -f UTF-8 en_US.UTF-8
RUN wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
&& tar -xzf Python-3.12.3.tgz
&& cd Python-3.12.3
&& sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
&& ./configure --enable-optimizations
&& make altinstall
Make runs for a while, and I even see a lot of unit tests pass. But ultimately, it is failing with this error:
#0 650.1 Programs/_bootstrap_python.o Modules/getpath.o -lpthread -ldl -lutil -lm
#0 650.7 ./_bootstrap_python ./Programs/_freeze_module.py abc ./Lib/abc.py Python/frozen_modules/abc.h
#0 650.8 Fatal Python error: init_import_site: Failed to import the site module
#0 650.8 Python runtime state: initialized
#0 650.8 Traceback (most recent call last):
#0 650.8 File "/Python-3.12.3/Lib/site.py", line 73, in <module>
#0 650.8 import os
#0 650.8 File "/Python-3.12.3/Lib/os.py", line 29, in <module>
#0 650.8 from _collections_abc import _check_methods
#0 650.8 SystemError: <built-in function compile> returned NULL without setting an exception
#0 650.8 make[1]: *** [Python/frozen_modules/abc.h] Error 1
#0 650.8 make[1]: Leaving directory `/Python-3.12.3'
#0 650.8 make: *** [profile-opt] Error 2
------
Dockerfile:13
--------------------
12 | # localedef -i en_US -f UTF-8 en_US.UTF-8
13 | >>> RUN wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
14 | >>> && tar -xzf Python-3.12.3.tgz
15 | >>> && cd Python-3.12.3
16 | >>> && sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
17 | >>> && ./configure --enable-optimizations
18 | >>> && make altinstall
19 |
--------------------
ERROR: failed to solve: process "/bin/bash -c wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz && tar -xzf Python-3.12.3.tgz && cd Python-3.12.3 && sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure && ./configure --enable-optimizations && make altinstall" did not complete successfully: exit code: 2
Docker version 24.0.2, build cb74dfc
Host OS : Ubuntu 18.04.1
Where have I gone wrong?
2
Answers
After a lot of experimentation, I was able to answer this question myself. The key pieces were getting devtoolset-10 installed along with openssl11 and properly referencing ssl11 from the configure utility.
Posting the solution here for anyone seeking the same. Here is the Dockerfile:
Despite a lot of fiddling I couldn’t get Python 3.12.3 to build, but here’s a
Dockerfile
that installs Python 3.10.14 onto Centos 7.For my understanding: