首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >构建Python包Docker镜像时出现Python错误

构建Python包Docker镜像时出现Python错误
EN

Stack Overflow用户
提问于 2018-12-13 08:12:05
回答 3查看 5.9K关注 0票数 7

我已经在RHEL7服务器上安装了Docker,并且它正在运行。我正在尝试构建我在GitHub上找到的第一个Docker Image,用于构建与Demisto一起使用的python库docker镜像。https://github.com/demisto/tools/tree/master/docker

我修改了requirements文件夹,只添加了一个python包impyla。正如您在下面看到的,它会下载并执行impyla及其依赖项,但随后会返回一条错误消息,但我不确定现在该怎么办。有没有有docker和/或python经验的人知道我下一步应该尝试什么?

[root@localhost docker]# sudo ./create_docker_image.sh dockerstuff/docker_python_image
Sending build context to Docker daemon 48.13kB
Step 1/3 : FROM python:2.7.15-slim-jessie
 ---> af47402d957b
Step 2/3 : COPY requirements.txt .
 ---> Using cache 
 ---> e107910d781c
Step 3/3 : RUN pip install --no-cache-dir -r requirements.txt
 ---> Running in 41e182aee016
Collecting impyla (from -r requirements.txt (line 1))
 Downloading https://files.pythonhosted.org/packages/6f/96/92f933cd216f9ff5d7f4ba7e0615a51ad4e3beb31a7de60f7df365378bb9/impyla-0.14.1-py2-none-any.whl (165kB)
Collecting six (from impyla->-r requirements.txt (line 1))
 Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl 
Collecting bitarray (from impyla->-r requirements.txt (line 1))
 Downloading https://files.pythonhosted.org/packages/e2/1e/b93636ae36d08d0ee3aec40b08731cc97217c69db9422c0afef6ee32ebd2/bitarray-0.8.3.tar.gz
Collecting thrift<=0.9.3 (from impyla->-r requirements.txt (line 1))
 Downloading https://files.pythonhosted.org/packages/ae/58/35e3f0cd290039ff862c2c9d8ae8a76896665d70343d833bdc2f748b8e55/thrift-0.9.3.tar.gz
Installing collected packages: six, bitarray, thrift, impyla
 Running setup.py install for bitarray: started
  Running setup.py install for bitarray: finished with status 'error'
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1p5nQr/bitarray/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-U39Tv0/install-record.txt --single-version-externally-managed --compile:
  running install
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/bitarray
  copying bitarray/__init__.py -> build/lib.linux-x86_64-2.7/bitarray
  copying bitarray/test_bitarray.py -> build/lib.linux-x86_64-2.7/bitarray
  running build_ext
  building 'bitarray._bitarray' extension
  creating build/temp.linux-x86_64-2.7/bitarray
  gcc -pthread -fno-strict-aliasing -g -02 -DNDEBUG -g -fwrapv -03 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c bitarray/_bitarray.c -o build/temp.linux-x86_64-2.7/bitarray/_bitarray.o
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1

  ------------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1p5nQr/bitarray/setup.py';f=getattr(tokensize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-U39Tv0/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-1p5nQr/bitarray/
The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-12-13 09:03:04

基本上,你必须自己添加所有的依赖项。第2行是我添加的内容,我刚刚修改了Dockerfile并自己构建了它。它起作用了。如果你有任何问题,请告诉我。

FROM python:2.7.15-slim-jessie

RUN apt-get update -y && apt-get install apt-file -y && apt-file update -y && apt-get install -y python3-dev build-essential

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt
票数 7
EN

Stack Overflow用户

发布于 2019-11-02 07:26:58

这适用于使用基于continuumio/miniconda3:latest的镜像并遇到unable to execute 'gcc'错误的任何人。我在Dockerfile中添加了下面这一行,这是我最基本的需求:

RUN apt-get update && apt-get -y install gcc

请注意,上图依次使用了debian:latest。而且,我也不需要所有的build-essential

票数 5
EN

Stack Overflow用户

发布于 2021-08-12 20:30:40

python3-devbuild-essential应该能满足包括gcc在内的大多数构建需求。

FROM python:3.6.13-slim
WORKDIR /app
COPY . .
RUN apt update -y && apt-get install -y python3-dev build-essential && \
    pip install -r requirements.txt 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53753267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档