skip to Main Content

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


  1. Chosen as BEST ANSWER

    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:

    FROM centos:7
    
    # Set bash as the default shell
    SHELL ["/bin/bash", "-c"]
    RUN yum -y update
    RUN yum install -y bzip2-devel libffi-devel zlib-devel gcc 
        wget epel-release.noarch 
        centos-release-scl scl-utils
    # Need to re-invoke yum after scl install
    RUN yum install -y openssl11 openssl11-devel devtoolset-10 
      && yum groupinstall -y "Development Tools" 
      
    RUN source scl_source enable devtoolset-10 
       && wget -q https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz 
       && tar -xzf Python-3.12.3.tgz
       && mkdir /usr/local/openssl11 
       && cd /usr/local/openssl11 
       && ln -s /usr/lib64/openssl11 lib 
       && ln -s /usr/include/openssl11 include 
       && cd /Python-3.12.3
       && export OPENSSL_LIBS=/usr/lib64/libssl.so 
       && ./configure 
       --with-openssl=/usr/local/openssl11 
       --with-openssl-rpath=/usr/lib64/openssl11 
       --enable-optimizations
    WORKDIR /Python-3.12.3
    RUN source scl_source enable devtoolset-10 
      && make altinstall 
      && cd / && rm -f Python-3.12.3.tgz 
      && rm -rf Python-3.12.3
      && yum -y groups remove "Development Tools"
      && yum -y remove devtoolset-10 centos-release-scl scl-utils
         bzip2-devel libffi-devel zlib-devel openssl11-devel 
      && yum clean all
      && rm -rf /var/cache/yum
    

  2. 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:

    • Would you consider a later version of Centos?
    • Is there specific functionality that you need in Python 3.12.3 or would another Python 3 version suffice?
    FROM centos:7
    
    ARG PYTHON_VERSION=3.10.14
    
    RUN yum -y update && 
        yum groupinstall -y "Development Tools" && 
        yum install -y 
            gcc 
            make 
            openssl-devel 
            bzip2-devel 
            libffi-devel 
            zlib-devel 
            wget 
            libuuid-devel 
            libsqlite3x-devel 
            readline-devel 
            tk-devel 
            gdbm-devel 
            db4-devel 
            libpcap-devel 
            xz-devel
    
    WORKDIR /usr/src
    RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && 
        tar -zxf Python-${PYTHON_VERSION}.tgz
    
    WORKDIR /usr/src/Python-${PYTHON_VERSION}
    RUN ./configure --enable-optimizations --enable-shared --with-ensurepip=install &&
        make altinstall
    
    RUN yum clean all && 
        rm -rf /var/cache/yum && 
        rm -rf /usr/src/Python-${PYTHON_VERSION}.tgz
    
    RUN ln -sf /usr/local/bin/python3.10 /usr/bin/python3 && 
        ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3
    
    ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search