在基于centos7的docker镜像中安装python 3.12.3

问题描述 投票:0回答:1

我正在尝试在基于centos7的docker镜像中安装python 3.12.3。我研究了如何做到这一点,似乎没有 Redhat 预构建的 rpm 可供安装,所以我唯一的选择是从源代码构建。按照网上的说明,我创建了这个 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

运行一段时间,我什至看到很多单元测试都通过了。但最终,它因以下错误而失败:

#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版本24.0.2,构建cb74dfc 主机操作系统:Ubuntu 18.04.1

我哪里出错了?

python-3.x docker centos7
1个回答
0
投票

尽管做了很多摆弄,我还是无法构建 Python 3.12.3,但这里有一个

Dockerfile
,可以将 Python 3.10.14 安装到 Centos 7 上。

据我了解:

  • 您会考虑使用更高版本的 Centos 吗?
  • Python 3.12.3 中是否有您需要的特定功能,或者其他 Python 3 版本就足够了吗?
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
© www.soinside.com 2019 - 2024. All rights reserved.