【问题标题】:Python error in docker - distutils.errors.CompileError: command 'gcc' failed with exit status 1docker 中的 Python 错误 - distutils.errors.CompileError: command 'gcc' failed with exit status 1
【发布时间】:2020-11-04 16:06:09
【问题描述】:

我正在尝试在 docker 映像中安装 google-cloud-pubsub。要求之一是安装 grpcio。在尝试安装 grpcio 时,我收到类似“distutils.errors.CompileError: command 'gcc' failed with exit status 1”的错误

我也安装了这些包 -> pip install --upgrade wheel numpy panda cython 6

使用的版本:Python 3.6.9 & pip 20.1.1 来自 /usr/lib/python3.6/site-packages/pip (python 3.6)

        Traceback (most recent call last):
    File "/tmp/pip-install-gtay96uw/grpcio/src/python/grpcio/commands.py", line 262, in build_extensions
      build_ext.build_ext.build_extensions(self)
    File "/usr/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
      _build_ext.build_ext.build_extensions(self)
    File "/usr/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
      self._build_extensions_serial()
    File "/usr/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
      self.build_extension(ext)
    File "/usr/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 208, in build_extension
      _build_ext.build_extension(self, ext)
    File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
      depends=ext.depends)
    File "/usr/lib/python3.6/distutils/ccompiler.py", line 574, in compile
      self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
    File "/tmp/pip-install-gtay96uw/grpcio/src/python/grpcio/commands.py", line 246, in new_compile
      pp_opts)
    File "/usr/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
      raise CompileError(msg)
  distutils.errors.CompileError: command 'gcc' failed with exit status 1

  ----------------------------------------
  **ERROR: Failed building wheel for grpcio
  Running setup.py clean for grpcio**

也尝试了其他版本的 google-cloud-pubsub -> 1.5.0、1.6.1。都以相同的错误结束。

我的 Docker 文件如下所示。

### 1. Get Linux
FROM alpine:3.7

### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre

#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
ENV PATH="$JAVA_HOME/bin:${PATH}"

RUN which java && java -version
RUN echo $PATH

#FROM python:3.7.5-alpine3.9
### 3. Get Python, PIP
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache

RUN apk --update add --no-cache gcc python3-dev musl-dev g++

RUN apk --update add gpgme-dev libc-dev

FROM gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
RUN gcloud components install gsutil bq

【问题讨论】:

标签: python-3.x docker gcc pip google-cloud-pubsub


【解决方案1】:

我在 alpine linux 上也遇到了这个问题。

apk add python-dev

用这段代码解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-20
    • 2020-10-13
    • 2019-03-19
    • 1970-01-01
    • 2015-11-09
    • 1970-01-01
    • 2019-07-04
    • 2019-09-20
    相关资源
    最近更新 更多