Building a docker image for a flask app fails in pip

2024/10/6 8:40:32
from alpine:latest
RUN apk add --no-cache python3-dev \&& pip3 install --upgrade pipWORKDIR /backend
COPY . /backendRUN pip --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ['python3']
CMD ['app.py']

I have a simple Dockerfile that looks like above.

When I do docker build -t backend:latest ., it gives me

ERROR: Command errored out with exit status 1: /usr/bin/python3.7 /usr/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-wr55ljb4/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel 'cffi>=1.1; python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
The command '/bin/sh -c pip --no-cache-dir install -r requirements.txt' returned a non-zero code: 1

Seems like my pip is not working properly. Any thoughts?

error log

Step 5/8 : RUN pip --no-cache-dir install -r requirements.txt---> Running in 22ceccf0fd82
Collecting asn1crypto==0.24.0 (from -r requirements.txt (line 1))Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
Collecting bcrypt==3.1.7 (from -r requirements.txt (line 2))Downloading https://files.pythonhosted.org/packages/fa/aa/025a3ab62469b5167bc397837c9ffc486c42a97ef12ceaa6699d8f5a5416/bcrypt-3.1.7.tar.gz (42kB)Installing build dependencies: startedInstalling build dependencies: finished with status 'error'ERROR: Command errored out with exit status 1:command: /usr/local/bin/python /usr/local/lib/python3.6/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-kjhqh8sc/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel 'cffi>=1.1; python_implementation != '"'"'PyPy'"'"''cwd: NoneComplete output (169 lines):Collecting setuptools>=40.8.0Downloading https://files.pythonhosted.org/packages/75/b3/0a106dfaf7f48aef638da80b32608617cc8de4b24a22c8cd3759c32e5d30/setuptools-41.1.0-py2.py3-none-any.whl (576kB)Collecting wheelDownloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whlCollecting cffi>=1.1Downloading https://files.pythonhosted.org/packages/93/1a/ab8c62b5838722f29f3daffcc8d4bd61844aa9b5f437341cc890ceee483b/cffi-1.12.3.tar.gz (456kB)Collecting pycparser (from cffi>=1.1)Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)Building wheels for collected packages: cffi, pycparserBuilding wheel for cffi (setup.py): startedBuilding wheel for cffi (setup.py): finished with status 'error'ERROR: Command errored out with exit status 1:command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-hdxzm2ih --python-tag cp36cwd: /tmp/pip-install-68ehjxmi/cffi/Complete output (68 lines):Package libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundunable to execute 'gcc': No such file or directoryunable to execute 'gcc': No such file or directoryNo working compiler found, or bogus compiler options passed tothe compiler from Python's standard "distutils" module.  Seethe error messages above.  Likely, the problem is not relatedto CFFI but generic to the setup.py of any Python package thattries 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 orthe IRC channel #python on irc.freenode.net.)Trying to continue anyway.  If you are trying to install CFFI froma build done in a different context, you can ignore this warning.running bdist_wheelrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-3.6creating build/lib.linux-x86_64-3.6/cfficopying cffi/cparser.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/lock.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/__init__.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/verifier.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/commontypes.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/recompiler.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/model.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/api.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/error.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/_embedding.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.6/cffirunning build_extbuilding '_cffi_backend' extensioncreating build/temp.linux-x86_64-3.6creating build/temp.linux-x86_64-3.6/cgcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.6m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.6/c/_cffi_backend.ounable to execute 'gcc': No such file or directoryerror: command 'gcc' failed with exit status 1----------------------------------------ERROR: Failed building wheel for cffiRunning setup.py clean for cffiBuilding wheel for pycparser (setup.py): startedBuilding wheel for pycparser (setup.py): finished with status 'done'Created wheel for pycparser: filename=pycparser-2.19-py2.py3-none-any.whl size=111031 sha256=7214a0d655238f2c9991c7a92ece87d949521239504b9dcc5b2e8ac2f438679aStored in directory: /root/.cache/pip/wheels/f2/9a/90/de94f8556265ddc9d9c8b271b0f63e57b26fb1d67a45564511Successfully built pycparserFailed to build cffiInstalling collected packages: setuptools, wheel, pycparser, cffiRunning setup.py install for cffi: startedRunning setup.py install for cffi: finished with status 'error'ERROR: Command errored out with exit status 1:command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oq4j1nik/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-kjhqh8sc/overlay --compilecwd: /tmp/pip-install-68ehjxmi/cffi/Complete output (68 lines):Package libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundPackage libffi was not found in the pkg-config search path.Perhaps you should add the directory containing `libffi.pc'to the PKG_CONFIG_PATH environment variablePackage 'libffi', required by 'virtual:world', not foundunable to execute 'gcc': No such file or directoryunable to execute 'gcc': No such file or directoryNo working compiler found, or bogus compiler options passed tothe compiler from Python's standard "distutils" module.  Seethe error messages above.  Likely, the problem is not relatedto CFFI but generic to the setup.py of any Python package thattries 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 orthe IRC channel #python on irc.freenode.net.)Trying to continue anyway.  If you are trying to install CFFI froma build done in a different context, you can ignore this warning.running installrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-3.6creating build/lib.linux-x86_64-3.6/cfficopying cffi/cparser.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/lock.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/__init__.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/verifier.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/commontypes.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/recompiler.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/model.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/api.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/error.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.6/cfficopying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/_embedding.h -> build/lib.linux-x86_64-3.6/cfficopying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.6/cffirunning build_extbuilding '_cffi_backend' extensioncreating build/temp.linux-x86_64-3.6creating build/temp.linux-x86_64-3.6/cgcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/usr/local/include/python3.6m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.6/c/_cffi_backend.ounable to execute 'gcc': No such file or directoryerror: command 'gcc' failed with exit status 1----------------------------------------ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-68ehjxmi/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oq4j1nik/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-kjhqh8sc/overlay --compile Check the logs for full command output.----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.6/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-kjhqh8sc/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel 'cffi>=1.1; python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
Answer

I struggled with that for a moment as well. I ended up creating my container with

FROM python:3.7-alpineRUN apk update && apk add gcc libc-dev make git libffi-dev openssl-dev python3-dev libxml2-dev libxslt-dev 

Anyway, if you want to use alpine:latest you probably just need some of the os dependencies I listed above.

https://en.xdnf.cn/q/70386.html

Related Q&A

Why is numba so fast?

I want to write a function which will take an index lefts of shape (N_ROWS,) I want to write a function which will create a matrix out = (N_ROWS, N_COLS) matrix such that out[i, j] = 1 if and only if j…

How to create a field with a list of foreign keys in SQLAlchemy?

I am trying to store a list of models within the field of another model. Here is a trivial example below, where I have an existing model, Actor, and I want to create a new model, Movie, with the field …

Implementing a recursive algorithm in pyspark to find pairings within a dataframe

I have a spark dataframe (prof_student_df) that lists student/professor pair for a timestamp. There are 4 professors and 4 students for each timestamp and each professor-student pair has a “score” (s…

Python Delegate Pattern - How to avoid circular reference?

I would to ask if using the Delegate Pattern in Python would lead to circular references and if so, what would be the best way to implement it to ensure the object and its delegate will be garbage coll…

Render Jinja after jQuery AJAX request to Flask

I have a web application that gets dynamic data from Flask when a select element from HTML is changed. of course that is done via jquery ajax. No probs here I got that.The problem is, the dynamic data …

shape-preserving piecewise cubic interpolation for 3D curve in python

I have a curve in 3D space. I want to use a shape-preserving piecewise cubic interpolation on it similar to pchip in matlab. I researched functions provided in scipy.interpolate, e.g. interp2d, but …

ForeignKey vs OneToOne field django [duplicate]

This question already has answers here:OneToOneField() vs ForeignKey() in Django(12 answers)Closed 9 years ago.I need to extend django user with some additional fields . I found 2 different ways there…

How to sort glob.glob numerically?

I have a bunch of files sorted numerically on a folder, when I try to sort glob.glob I never get the files in the right order.file examples and expected output sorting folder ------ C:\Users\user\Deskt…

How to determine a numpy-array reshape strategy

For a python project I often find myself reshaping and re-arranging n-dimensional numpy arrays. However, I have a hard time to determine how to approach the problem, visualize the outcome of the result…

matplotlib plotting multiple lines in 3D

I am trying to plot multiple lines in a 3D plot using matplotlib. I have 6 datasets with x and y values. What Ive tried so far was, to give each point in the data sets a z-value. So all points in data …