Docker 无法在 Docker 文件中使用 python:3.9-alpine 安装 cffi
Docker fails to install cffi with python:3.9-alpine in Dockerfile
我正在尝试使用 docker-compose 运行 下面的 Docker 文件。
我四处搜索,但找不到有关如何使用 python:3.9-alpine.
安装 cffi 的解决方案
我也读过这个post,其中指出 pip 21.2.4 或更高版本可能是一个可能的解决方案,但我没有解决
https://www.pythonfixing.com/2021/09/fixed-why-i-getting-this-error-while.html
Docker 文件
FROM python:3.9-alpine
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt .
RUN apk add --update --no-cache postgresql-client
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev
RUN pip3 install --upgrade pip && pip3 install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN adduser -D user
USER user
这是 requirements.txt 文件。
asgiref==3.5.0
backports.zoneinfo==0.2.1
certifi==2021.10.8
cffi==1.15.0
cfgv==3.3.1
...
错误信息:
process-exited-with-error
#9 47.99
#9 47.99 × Running setup.py install for cffi did not run successfully.
#9 47.99 │ exit code: 1
#9 47.99 ╰─> [58 lines of output]
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 running install
#9 47.99 running build
#9 47.99 running build_py
#9 47.99 creating build
#9 47.99 creating build/lib.linux-aarch64-3.9
#9 47.99 creating build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/__init__.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/cffi_opcode.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/commontypes.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/vengine_gen.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/vengine_cpy.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/backend_ctypes.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/api.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/ffiplatform.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/verifier.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/error.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/setuptools_ext.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/lock.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/recompiler.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/pkgconfig.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/cparser.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/model.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_cffi_include.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/parse_c_type.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_embedding.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_cffi_errors.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 warning: build_py: byte-compiling is disabled, skipping.
#9 47.99
#9 47.99 running build_ext
#9 47.99 building '_cffi_backend' extension
#9 47.99 creating build/temp.linux-aarch64-3.9
#9 47.99 creating build/temp.linux-aarch64-3.9/c
#9 47.99 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-aarch64-3.9/c/_cffi_backend.o
#9 47.99 c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#9 47.99 15 | #include <ffi.h>
#9 47.99 | ^~~~~~~
#9 47.99 compilation terminated.
#9 47.99 error: command '/usr/bin/gcc' failed with exit code 1
#9 47.99 [end of output]
#9 47.99
#9 47.99 note: This error originates from a subprocess, and is likely not a problem with pip.
#9 47.99 error: legacy-install-failure
#9 47.99
#9 47.99 × Encountered error while trying to install package.
#9 47.99 ╰─> cffi
#9 47.99
#9 47.99 note: This is an issue with the package mentioned above, not pip.
#9 47.99 hint: See above for output from the failure.
缺少 libffi 库。
将其添加到您的 dockerfile 中:
RUN apk add libffi-dev
@Klaus D. 的评论帮助很大。
我更新了 Dockerfile:
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev \
&& apk add libffi-dev
我正在尝试使用 docker-compose 运行 下面的 Docker 文件。 我四处搜索,但找不到有关如何使用 python:3.9-alpine.
安装 cffi 的解决方案我也读过这个post,其中指出 pip 21.2.4 或更高版本可能是一个可能的解决方案,但我没有解决
https://www.pythonfixing.com/2021/09/fixed-why-i-getting-this-error-while.html
Docker 文件
FROM python:3.9-alpine
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt .
RUN apk add --update --no-cache postgresql-client
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev
RUN pip3 install --upgrade pip && pip3 install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN adduser -D user
USER user
这是 requirements.txt 文件。
asgiref==3.5.0
backports.zoneinfo==0.2.1
certifi==2021.10.8
cffi==1.15.0
cfgv==3.3.1
...
错误信息:
process-exited-with-error
#9 47.99
#9 47.99 × Running setup.py install for cffi did not run successfully.
#9 47.99 │ exit code: 1
#9 47.99 ╰─> [58 lines of output]
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 Package libffi was not found in the pkg-config search path.
#9 47.99 Perhaps you should add the directory containing `libffi.pc'
#9 47.99 to the PKG_CONFIG_PATH environment variable
#9 47.99 Package 'libffi', required by 'virtual:world', not found
#9 47.99 running install
#9 47.99 running build
#9 47.99 running build_py
#9 47.99 creating build
#9 47.99 creating build/lib.linux-aarch64-3.9
#9 47.99 creating build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/__init__.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/cffi_opcode.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/commontypes.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/vengine_gen.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/vengine_cpy.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/backend_ctypes.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/api.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/ffiplatform.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/verifier.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/error.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/setuptools_ext.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/lock.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/recompiler.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/pkgconfig.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/cparser.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/model.py -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_cffi_include.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/parse_c_type.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_embedding.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 copying cffi/_cffi_errors.h -> build/lib.linux-aarch64-3.9/cffi
#9 47.99 warning: build_py: byte-compiling is disabled, skipping.
#9 47.99
#9 47.99 running build_ext
#9 47.99 building '_cffi_backend' extension
#9 47.99 creating build/temp.linux-aarch64-3.9
#9 47.99 creating build/temp.linux-aarch64-3.9/c
#9 47.99 gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.9 -c c/_cffi_backend.c -o build/temp.linux-aarch64-3.9/c/_cffi_backend.o
#9 47.99 c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#9 47.99 15 | #include <ffi.h>
#9 47.99 | ^~~~~~~
#9 47.99 compilation terminated.
#9 47.99 error: command '/usr/bin/gcc' failed with exit code 1
#9 47.99 [end of output]
#9 47.99
#9 47.99 note: This error originates from a subprocess, and is likely not a problem with pip.
#9 47.99 error: legacy-install-failure
#9 47.99
#9 47.99 × Encountered error while trying to install package.
#9 47.99 ╰─> cffi
#9 47.99
#9 47.99 note: This is an issue with the package mentioned above, not pip.
#9 47.99 hint: See above for output from the failure.
缺少 libffi 库。
将其添加到您的 dockerfile 中:
RUN apk add libffi-dev
@Klaus D. 的评论帮助很大。 我更新了 Dockerfile:
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev \
&& apk add libffi-dev