在构建映像时,获取“命令'/ bin / sh -c pip install -r requirements.txt”返回了非零代码:1Docker Container

问题描述

我正在尝试使用Cloud Shell中的python应用程序构建docker映像。

但是我不断得到The command /bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1 出现以下错误

In file included from /usr/local/include/python3.9/unicodeobject.h:1026,from /usr/local/include/python3.9/Python.h:97,from numpy/random/mtrand/mtrand.c:4:
      /usr/local/include/python3.9/cpython/unicodeobject.h:580:45: note: declared here
       Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
                                                   ^~~~~~~~~~~~~~~~~~~
      numpy/random/mtrand/mtrand.c:45406:25: warning: ‘_PyUnicode_get_wstr_length’ is deprecated [-Wdeprecated-declarations]
                               (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                               ^
      In file included from /usr/local/include/python3.9/unicodeobject.h:1026,from numpy/random/mtrand/mtrand.c:4:
      /usr/local/include/python3.9/cpython/unicodeobject.h:446:26: note: declared here
       static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~
      error: Command "gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1
 -Inumpy/core/include -Ibuild/src.linux-x86_64-3.9/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/
multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/local/include/python3.9 -Ibuild/src.linux-x86_64-3.9/numpy/core/src/private -Ibuild/src.linux-x86_64-3.9/nu
mpy/core/src/npymath -Ibuild/src.linux-x86_64-3.9/numpy/core/src/private -Ibuild/src.linux-x86_64-3.9/numpy/core/src/npymath -Ibuild/src.linux-x86_64-3.9/numpy/core/src/priv
ate -Ibuild/src.linux-x86_64-3.9/numpy/core/src/npymath -c numpy/random/mtrand/mtrand.c -o build/temp.linux-x86_64-3.9/numpy/random/mtrand/mtrand.o -MMD -MF build/temp.linux
-x86_64-3.9/numpy/random/mtrand/mtrand.o.d" 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-x4qlx1an/numpy/setup.py'"
'"'; __file__='"'"'/tmp/pip-install-x4qlx1an/numpy/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.cl
ose();exec(compile(code,__file__,'"'"'exec'"'"'))' install --record /tmp/pip-record-9i48k0hd/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build
-env-84xomudw/overlay --compile --install-headers /tmp/pip-build-env-84xomudw/overlay/include/python3.9/numpy Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-
env-84xomudw/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'Cython>=0.29.13' 'numpy==1.13.3; pytho
n_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.14.5; python_version>='"'"'3.7'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0; python_version
=='"'"'3.6'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version>='"'"'3.7'"'"' and platform_system=='"'"'AIX'"'"'' Check the logs for full command output.


dockerfile包含以下内容

FROM python:3
workdir /app
ADD . /app

RUN pip install -r requirements.txt

EXPOSE 80

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

有什么建议吗?

解决方法

我也遇到过这个问题,最后从 Heroku 得到了解决方案。实际上,Heroku 上的新 Python 应用程序使用指定 Python 版本(默认为新版本的 Python)中指示的 Python 运行时。要解决此问题,您必须创建一个 runtime.txt 文件,您可以在其中编写用于创建环境的 Python 版本。 Heroku 支持以下 python 版本-

  1. python-3.9.4
  2. python-3.8.9
  3. python-3.7.10
  4. python-3.6.13

下面是runtime.txt文件的快照

enter image description here

创建此文件后,将其放入我们应用的根目录中。

enter image description here

然后按照通常的程序进行部署。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...