Im trying to run the below Dockerfile using docker-compose. I searched around but I couldnt find a solution on how to install cffi with python:3.9-alpine.
I also read this post which states that pip 21.2.4 or greater can be a possible solution but it didn't work out form me
https://www.pythonfixing.com/2021/09/fixed-why-i-getting-this-error-while.html
Docker file
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
This is the requirements.txt file.
asgiref==3.5.0
backports.zoneinfo==0.2.1
certifi==2021.10.8
cffi==1.15.0
cfgv==3.3.1
...
Error message:
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.