软件包未使用 Dockerfile 安装

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

我是 python 新手,使用 python:3.7.13-alpine3.15 docker 映像,在下载软件包时,我看到以下错误。有人可以建议一些吗?

我已经尝试将 docker 映像更改为非 alpine 映像。但这没有帮助。

错误:


执行器运行失败 [/bin/sh -c apk add --no-cache --virtual .build-deps g++ libxml2 libxml2-dev alpine-sdk py3-cffi libffi-dev libxslt-dev python3-dev]:退出代码: 2

Docker 文件:

FROM python:3.7.13-alpine3.15
RUN apk update
RUN apk add --no-cache --virtual .build-deps g++ libxml2 libxml2-dev alpine-sdk py3-cffi libffi-dev libxslt-dev python3-dev
RUN pip install --upgrade pip setuptools
RUN pip --version
RUN python --version
WORKDIR ./
RUN apk add --update alpine-sdk py3-cffi libffi-dev
RUN python -m venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip3 install -Ur "requirements.txt"

需求.txt: 正在安装以下软件包

    beautifulsoup4==4.9.3
    certifi==2020.12.5
    chardet==4.0.0
    idna==2.10
    lxml==4.6.2
    nuclio-sdk==0.2.0
    pycparser==2.20
    PyJWT==2.0.1
    pymongo==3.11.2
    pysolr==3.9.0
    py7zr==0.16.1
    python-memcached==1.59
    PyYAML==5.4
    requests==2.25.1
    six==1.15.0
    urllib3==1.26.2
    zeep==4.1.0
    requests-kerberos==0.14.0
python docker
2个回答
0
投票

如果我在 shell 中使用该图像

pip install bcj-cffi
,错误消息将更具描述性并指出问题的根源:

$ docker run -it --rm python:3.7.13-alpine3.15 sh
/ # pip install bcj-cffi
Collecting bcj-cffi
  Downloading bcj-cffi-0.5.1.tar.gz (35 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... error
  error: subprocess-exited-with-error


        × Running setup.py install for cffi did not run successfully.
        │ exit code: 1
        ╰─> [48 lines of output]
            unable to execute 'gcc': No such file or directory
            unable to execute 'gcc': No such file or directory

                No working compiler found, or bogus compiler options passed to
                the compiler from Python's standard "distutils" module.  See
                the error messages above.  Likely, the problem is not related
                to CFFI but generic to the setup.py of any Python package that
                tries to compile C code.  (Hints: on OS/X 10.8, for errors about
                -mno-fused-madd see http://stackoverflow.com/questions/22313407/
                Otherwise, see https://wiki.python.org/moin/CompLangPython or
                the IRC channel #python on irc.libera.chat.)
  ...

这里的问题是

bcj-cffi
模块有许多非 Python 依赖项。为了成功安装
bcf-cffi
,我必须先安装:

apk add --update alpine-sdk py3-cffi libffi-dev

在此之后,我能够成功地

pip install bcj-cffi

alpine-sdk
包实际上是“合理的 C 构建环境”的简写。)


0
投票

我的案例的解决方案是因为我在 DockerFile 上使用了“alpine”图像。避免使用 alpine,就我而言,它导致了与我的 MacOs M1 不兼容的问题

© www.soinside.com 2019 - 2024. All rights reserved.