python中compiled error,泊坞窗中的Python错误-distutils.errors.CompileError:命令'gcc'失败,退出状态为1...

I am trying to install google-cloud-pubsub in a docker image. One of the requirement is to install grpcio. While trying to install grpcio, I get an error like "distutils.errors.CompileError: command 'gcc' failed with exit status 1"

I have also installed these packages -> pip install --upgrade wheel numpy panda cython six

Version used : Python 3.6.9 & pip 20.1.1 from /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**

Tried other version of google-cloud-pubsub as well -> 1.5.0, 1.6.1. All ending with the same error.

My Docker file looks like below.

### 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

解决方案

I was also getting this problem on alpine linux.

apk add python-dev

solved with this code.