Docker image python:3.12-alpine在Windows和Debian上的行为不同

h5qlskok  于 2024-01-06  发布在  Docker
关注(0)|答案(1)|浏览(209)

此问题在此处已有答案

Docker fails to install cffi with python:3.9-alpine in Dockerfile(3个答案)
19天前关闭。
我已经在我的Windows机器上构建了我的Fastapi项目,我可以成功地运行它并构建映像。
但是当我想在Raspberry Pi 4上运行项目时,Debian 12 Bookworm docker --version > v24.0.7,它失败了,同时告诉我它找不到C编译器(gcc)。
它在pip安装来自requirements.txt的软件包的步骤中失败。
Dockerfile

FROM python:3.12-alpine
LABEL authors="Raphael2b3"

ADD requirements.txt ./

RUN pip install --upgrade pip

RUN pip install -r requirements.txt

RUN rm -f ./requirements.txt

ADD . ./src

WORKDIR ./src

CMD ["python", "main.py"]

字符串
requirements.txt

neo4j
python-dotenv
passlib
python-jose[cryptography]
passlib[bcrypt]
pytest
pytest-asyncio
pytest-order
starlette
pydantic
fastapi[all]
uvicorn[standard]


Debian 12上的Raspberry Pi错误日志:

18.55 Collecting cryptography>=3.4.0 (from python-jose[cryptography]->-r requirements.txt (line 4))
18.58   Downloading cryptography-41.0.7.tar.gz (630 kB)
18.68      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 630.9/630.9 kB 6.9 MB/s eta 0:00:00
19.16   Installing build dependencies: started
33.19   Installing build dependencies: finished with status 'error'
33.23   error: subprocess-exited-with-error
33.23
33.23   × pip subprocess to install build dependencies did not run successfully.
33.23   │ exit code: 1
33.23   ╰─> [87 lines of output]
33.23       Collecting setuptools>=61.0.0
33.23         Using cached setuptools-69.0.2-py3-none-any.whl.metadata (6.3 kB)
33.23       Collecting wheel
33.23         Using cached wheel-0.42.0-py3-none-any.whl.metadata (2.2 kB)
33.23       Collecting cffi>=1.12
33.23         Downloading cffi-1.16.0.tar.gz (512 kB)
33.23            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 512.9/512.9 kB 4.3 MB/s eta 0:00:00
33.23         Installing build dependencies: started
33.23         Installing build dependencies: finished with status 'done'
33.23         Getting requirements to build wheel: started
33.23         Getting requirements to build wheel: finished with status 'done'
33.23         Installing backend dependencies: started
33.23         Installing backend dependencies: finished with status 'done'
33.23         Preparing metadata (pyproject.toml): started
33.23         Preparing metadata (pyproject.toml): finished with status 'done'
33.23       Collecting setuptools-rust>=0.11.4
33.23         Downloading setuptools_rust-1.8.1-py3-none-any.whl.metadata (9.4 kB)
33.23       Collecting pycparser (from cffi>=1.12)
33.23         Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
33.23            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 3.3 MB/s eta 0:00:00
33.23       Collecting semantic-version<3,>=2.8.2 (from setuptools-rust>=0.11.4)
33.23         Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)
33.23       Using cached setuptools-69.0.2-py3-none-any.whl (819 kB)
33.23       Using cached wheel-0.42.0-py3-none-any.whl (65 kB)
33.23       Downloading setuptools_rust-1.8.1-py3-none-any.whl (26 kB)
33.23       Building wheels for collected packages: cffi
33.23         Building wheel for cffi (pyproject.toml): started
33.23         Building wheel for cffi (pyproject.toml): finished with status 'error'
33.23         error: subprocess-exited-with-error
33.23
33.23         × Building wheel for cffi (pyproject.toml) did not run successfully.
33.23         │ exit code: 1
33.23         ╰─> [48 lines of output]
33.23
33.23                 No working compiler found, or bogus compiler options passed to
33.23                 the compiler from Python's standard "distutils" module.  See
33.23                 the error messages above.  Likely, the problem is not related
33.23                 to CFFI but generic to the setup.py of any Python package that
33.23                 tries to compile C code.  (Hints: on OS/X 10.8, for errors about
33.23                 -mno-fused-madd see http://stackoverflow.com/questions/22313407/
33.23                 Otherwise, see https://wiki.python.org/moin/CompLangPython or
33.23                 the IRC channel #python on irc.libera.chat.)
33.23
33.23                 Trying to continue anyway.  If you are trying to install CFFI from
33.23                 a build done in a different context, you can ignore this warning.
33.23
33.23             running bdist_wheel
33.23             running build
33.23             running build_py
33.23             creating build
33.23             creating build/lib.linux-aarch64-cpython-312
33.23             creating build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/cffi_opcode.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/verifier.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/api.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/pkgconfig.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/_imp_emulation.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/vengine_gen.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/error.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/ffiplatform.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/__init__.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/setuptools_ext.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/lock.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/_shimmed_dist_utils.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/backend_ctypes.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/recompiler.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/commontypes.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/vengine_cpy.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/cparser.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/model.py -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/_cffi_include.h -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/parse_c_type.h -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/_embedding.h -> build/lib.linux-aarch64-cpython-312/cffi
33.23             copying src/cffi/_cffi_errors.h -> build/lib.linux-aarch64-cpython-312/cffi
33.23             running build_ext
33.23             building '_cffi_backend' extension
33.23             creating build/temp.linux-aarch64-cpython-312
33.23             creating build/temp.linux-aarch64-cpython-312/src
33.23             creating build/temp.linux-aarch64-cpython-312/src/c
33.23             gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DFFI_BUILDING=1 -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.12 -c src/c/_cffi_backend.c -o build/temp.linux-aarch64-cpython-312/src/c/_cffi_backend.o
33.23             error: command 'gcc' failed: No such file or directory
33.23             [end of output]
33.23
33.23         note: This error originates from a subprocess, and is likely not a problem with pip.
33.23         ERROR: Failed building wheel for cffi
33.23       Failed to build cffi
33.23       ERROR: Could not build wheels for cffi, which is required to install pyproject.toml-based projects
33.23       [end of output]
33.23
33.23   note: This error originates from a subprocess, and is likely not a problem with pip.
33.23 error: subprocess-exited-with-error
33.23
33.23 × pip subprocess to install build dependencies did not run successfully.
33.23 │ exit code: 1
33.23 ╰─> See above for output.
33.23
33.23 note: This error originates from a subprocess, and is likely not a problem with pip.
------
failed to solve: process "/bin/sh -c pip install -r requirements.txt" did not complete successfully: exit code: 1
message.txt
8 kB


是否有有效的解决方法?这是否是一个应该报告的问题?

yh2wf1be

yh2wf1be1#

看起来它正在尝试为cffi构建wheel。你能尝试用--no-binary和/或--no-index运行pip install并强制它找到wheel吗?
或者,你必须使用apt-get安装gcc,这在安装和编译时会非常慢,并导致一个更大的映像。
也可以删除RUN rm -f ./requirements.txt,它不必要地增加了图像的大小和图层。

相关问题