Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在docker容器中运行pip install适用于除依赖项注入器之外的每个python包_Python 3.x_Docker_Dependency Injection_Docker Compose_Dockerfile - Fatal编程技术网

Python 3.x 在docker容器中运行pip install适用于除依赖项注入器之外的每个python包

Python 3.x 在docker容器中运行pip install适用于除依赖项注入器之外的每个python包,python-3.x,docker,dependency-injection,docker-compose,dockerfile,Python 3.x,Docker,Dependency Injection,Docker Compose,Dockerfile,docker文件中有以下内容: FROM python:3.7.5-alpine3.10 as base FROM base as builder RUN mkdir /install WORKDIR /install COPY dependencies.txt /dependencies.txt RUN pip install --install-option="--prefix=/install" -r /dependencies.txt

docker文件中有以下内容:

    FROM python:3.7.5-alpine3.10 as base

    FROM base as builder
    RUN mkdir /install
    WORKDIR /install
    COPY dependencies.txt /dependencies.txt
    RUN pip install --install-option="--prefix=/install" -r /dependencies.txt
dependencies.txt如下所示:

    multitasking
    dependency-injector
如果删除了dependency injector,它将安装所有软件包,但在dependency injector存在的情况下,当docker映像生成时,我得到以下错误:

The command '/bin/sh -c pip install --trusted-host pypi.python.org -r /requirements.txt' returned a non-zero code: 1
    (base) cosmos@ubuntu:~/git/newest/bigbang/bb-collector/partial_profiler$ sudo ./build_container.sh 
    Building common and partial_profiler container
    Sending build context to Docker daemon  625.2kB
    Step 1/14 : FROM python:3.7.5-alpine3.10 as base
     ---> 8922d588eec6
    Step 2/14 : FROM base as builder
     ---> 8922d588eec6
    Step 3/14 : RUN mkdir /install
     ---> Using cache
     ---> 3f62ef86c42b
    Step 4/14 : WORKDIR /install
     ---> Using cache
     ---> acc30ad7c3e7
    Step 5/14 : COPY dependencies.txt /dependencies.txt
     ---> Using cache
     ---> 9722c2a49839
    Step 6/14 : RUN pip install --trusted-host pypi.python.org -r /dependencies.txt
     ---> Running in 9f44aa710486
    Collecting redis
      Downloading https://files.pythonhosted.org/packages/f0/05/1fc7feedc19c123e7a95cfc9e7892eb6cdd2e5df4e9e8af6384349c1cc3d/redis-3.4.1-py2.py3-none-any.whl (71kB)
    Collecting kafka-python
      Downloading https://files.pythonhosted.org/packages/aa/34/12f219f7f9e68e79a54874d26fbe974db1ab4efac4e6dae665b421df48f9/kafka_python-2.0.1-py2.py3-none-any.whl (232kB)
    Collecting multitasking
      Downloading https://files.pythonhosted.org/packages/69/e7/e9f1661c28f7b87abfa08cb0e8f51dad2240a9f4f741f02ea839835e6d18/multitasking-0.0.9.tar.gz
    Collecting dependency-injector
      Downloading https://files.pythonhosted.org/packages/f3/9a/344c06f03503046260116e4f2a9887d8f720a3914c760c81b78d47a9f926/dependency-injector-3.15.6.tar.gz (334kB)
    Collecting six<=1.14.0,>=1.7.0
      Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
    Building wheels for collected packages: multitasking, dependency-injector
      Building wheel for multitasking (setup.py): started
      Building wheel for multitasking (setup.py): finished with status 'done'
      Created wheel for multitasking: filename=multitasking-0.0.9-cp37-none-any.whl size=8368 sha256=cc3d1d0a59d461567e563485f6306110069122913b1d5f2ea6b1f2cb7c9c7a45
      Stored in directory: /root/.cache/pip/wheels/37/fa/73/d492849e319038eb4d986f5152e4b19ffb1bc0639da84d2677
      Building wheel for dependency-injector (setup.py): started
      Building wheel for dependency-injector (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-2kkjw147/dependency-injector/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2kkjw147/dependency-injector/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-zjrhhvrm --python-tag cp37
           cwd: /tmp/pip-install-2kkjw147/dependency-injector/
      Complete output (18 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.7
      creating build/lib.linux-x86_64-3.7/dependency_injector
      copying src/dependency_injector/errors.py -> build/lib.linux-x86_64-3.7/dependency_injector
      copying src/dependency_injector/__init__.py -> build/lib.linux-x86_64-3.7/dependency_injector
      copying src/dependency_injector/containers.pxd -> build/lib.linux-x86_64-3.7/dependency_injector
      copying src/dependency_injector/providers.pxd -> build/lib.linux-x86_64-3.7/dependency_injector
      running build_ext
      building 'dependency_injector.containers' extension
      creating build/temp.linux-x86_64-3.7
      creating build/temp.linux-x86_64-3.7/src
      creating build/temp.linux-x86_64-3.7/src/dependency_injector
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -I/usr/local/include/python3.7m -c src/dependency_injector/containers.c -o build/temp.linux-x86_64-3.7/src/dependency_injector/containers.o -O2
      unable to execute 'gcc': No such file or directory
      error: command 'gcc' failed with exit status 1
      ----------------------------------------
      ERROR: Failed building wheel for dependency-injector
命令'/bin/sh-cpip install--trusted host pypi.python.org-r/requirements.txt'返回一个非零代码:1
(基数)cosmos@ubuntu:~/git/latest/bigbang/bb collector/partial\u profiler$sudo./build\u container.sh
构建通用和部分_探查器容器
将生成上下文发送到Docker守护程序625.2kB
步骤1/14:来自python:3.7.5-alpine3.10作为基础
--->8922d588eec6
步骤2/14:作为构建者从基础开始
--->8922d588eec6
步骤3/14:运行mkdir/install
--->使用缓存
--->3f62ef86c42b
步骤4/14:WORKDIR/安装
--->使用缓存
--->acc30ad7c3e7
步骤5/14:复制dependencies.txt/dependencies.txt
--->使用缓存
--->9722c2a49839
步骤6/14:运行pip安装——可信主机pypi.python.org-r/dependencies.txt
--->在9f44aa710486中运行
收集redis
正在下载https://files.pythonhosted.org/packages/f0/05/1fc7feedc19c123e7a95cfc9e7892eb6cdd2e5df4e9e8af6384349c1cc3d/redis-3.4.1-py2.py3-none-any.whl (71kB)
收集卡夫卡巨蟒
正在下载https://files.pythonhosted.org/packages/aa/34/12f219f7f9e68e79a54874d26fbe974db1ab4efac4e6dae665b421df48f9/kafka_python-2.0.1-py2.py3-none-any.whl (232kB)
收集多任务
正在下载https://files.pythonhosted.org/packages/69/e7/e9f1661c28f7b87abfa08cb0e8f51dad2240a9f4f741f02ea839835e6d18/multitasking-0.0.9.tar.gz
收集依赖项注入器
正在下载https://files.pythonhosted.org/packages/f3/9a/344c06f03503046260116e4f2a9887d8f720a3914c760c81b78d47a9f926/dependency-injector-3.15.6.tar.gz (334kB)
收集六个=1.7.0
正在下载https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
为收集的包构建轮子:多任务、依赖关系注入
构建多任务控制盘(setup.py):已启动
构建多任务控制盘(setup.py):完成状态为“完成”
为多任务创建的控制盘:文件名=多任务-0.0.9-cp37-none-any.whl size=8368 sha256=CC3D1D0A59D46567E563485F6306100069122913B1D5F2EA6B1F2CB7C9A45
存储在目录:/root/.cache/pip/wheels/37/fa/73/d492849e319038eb4d986f5152e4b19ffb1bc0639da84d2677中
为依赖项注入器构建控制盘(setup.py):已启动
为依赖项注入器(setup.py)构建控制盘:已完成,状态为“error”
错误:命令出错,退出状态为1:
命令:/usr/local/bin/python-u-c'import sys、setuptools、tokenize;sys.argv[0]=“”/tmp/pip-install-2kkjw147/dependency injector/setup.py”“”__文件\ \='''''''/tmp/pip-install-2kkjw147/dependency injector/setup.py''';f=getattr(标记化,“'open'”,open)(\uuuuu文件);code=f.read().replace(“\r\n”“”、“\n”“”);f、 close();exec(编译(代码,uuuu文件,“'exec'”)'bdist_wheel-d/tmp/pip wheel zjrhhvrm——python标记cp37
cwd:/tmp/pip-install-2kkjw147/依赖性注入器/
完整输出(18行):
运转的车轮
运行构建
运行build\u py
创建构建
创建build/lib.linux-x86_64-3.7
创建build/lib.linux-x86\u 64-3.7/dependency\u
正在复制src/dependency\u injector/errors.py->build/lib.linux-x86\u 64-3.7/dependency\u injector
正在复制src/dependency\u injector/\uuuuu init\uuuu.py->build/lib.linux-x86\u 64-3.7/dependency\u injector
正在复制src/dependency\u injector/containers.pxd->build/lib.linux-x86\u 64-3.7/dependency\u injector
正在复制src/dependency\u injector/providers.pxd->build/lib.linux-x86\u 64-3.7/dependency\u injector
运行build_ext
正在生成“依赖关系容器”扩展
创建build/temp.linux-x86_64-3.7
创建build/temp.linux-x86_64-3.7/src
创建build/temp.linux-x86\u 64-3.7/src/dependency\u注入器
gcc-Wno unused result-Wsign compare-DNDEBUG-g-fwrapv-O3-Wall-DTHREAD_STACK_SIZE=0x100000-fPIC-DCYTHON_CLINE_IN_TRACEBACK=0-I/usr/local/include/python3.7m-c src/dependency_injector/containers.c-o build/temp.linux-x86_64-3.7/src/dependency_injector/containers.o-O2
无法执行“gcc”:没有这样的文件或目录
错误:命令“gcc”失败,退出状态为1
----------------------------------------
错误:为依赖项注入器生成控制盘失败

这就是我得到的错误。但是,如果我尝试在docker外部(即在我的Ubuntu盒中)使用pip安装依赖项注入器进行安装,它会工作

您需要gcc和一些其他软件包来构建此软件包。将下面的行添加到docker文件,它将解决此问题

RUN apk update && apk add g++
完整示例

 FROM python:3.7.5-alpine3.10 as base
 RUN apk update && apk add g++

 FROM base as builder
 RUN mkdir /install
 WORKDIR /install
 COPY dependencies.txt /dependencies.txt
 RUN pip install --install-option="--prefix=/install" -r /dependencies.txt

谢谢@Al waleed给我gcc的提示。上述方法对我来说不起作用,但以下方法起作用了:运行apk update&\apk add g++I更新了解决方案,以防其他人需要它