Docker 镜像 python:3.12-apline 在 Windows 和 Debian 上的行为不同

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

我已经在 Windows 机器上构建了我的 fastapi 项目,我可以成功运行它并构建图像

但是当我想在带有 Debian 12 Bookworm 的 Raspberry Pi 上运行该项目时,

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"]

需求.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

是否有有效的解决方法,这是一个应该在某处报告的问题吗?

亲切的问候

python docker raspberry-pi debian docker-image
1个回答
0
投票

看起来它正在尝试为 cffi 造轮子。您可以尝试使用

--no-binary
和/或
--no-index
运行 pip install 并强制它找到轮子吗? 或者,您必须使用 apt-get 安装 gcc

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