我正在试着使用一个pupsub仿真器。它启动了,但是当我尝试使用我的python脚本时,我得到了以下错误
ModuleNotFoundError: No module named 'google'所以我试着安装这个模块。
RUN pip install google-cloud-pubsub错误
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-2hyoy1ly/grpcio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2hyoy1ly/grpcio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-m25l52fe
cwd: /tmp/pip-install-2hyoy1ly/grpcio/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-2hyoy1ly/grpcio/setup.py", line 191, in <module>
if check_linker_need_libatomic():
File "/tmp/pip-install-2hyoy1ly/grpcio/setup.py", line 152, in check_linker_need_libatomic
stderr=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cc': 'cc'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Service 'praise-pubsub' failed to build: The command '/bin/sh -c pip install google-cloud-pubsub==0.24.0' returned a non-zero code: 1完整的Dockerfile
FROM google/cloud-sdk:alpine
RUN gcloud components install pubsub-emulator
FROM openjdk:jre-alpine
ENV PYTHONUNBUFFERED=1
RUN echo "**** install Python ****" && \
apk add --no-cache python3 && \
if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi && \
\
echo "**** install pip ****" && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --no-cache --upgrade pip setuptools wheel && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi
#RUN pip install google-cloud <--- still fails when this is here
#RUN pip install Cython --install-option="--no-cython-compile" <--- still fails
RUN pip install google-cloud-pubsub
COPY --from=0 /google-cloud-sdk/platform/pubsub-emulator /pubsub-emulator发布于 2020-09-24 14:45:33
我不知道你为什么要安装python3和pip3,它们都存在于基础镜像中。在任何情况下,这个Dockerfile都会以一个漂亮干净的图像向您提供python google-cloud-pubsub库
FROM google/cloud-sdk:alpine
RUN apk add --no-cache --virtual .build-deps \
linux-headers build-base g++ python3-dev \
&& pip3 install --no-cache-dir google-cloud-pubsub \
&& apk del .build-deps
# add your stuff here发布于 2020-06-08 19:12:32
看起来为了安装这个客户端,你需要在你的docker容器中安装gcc。它正在尝试使用cc命令来编译库的一部分。尝试在安装google-cloud-pubsub包之前安装cython包。
还值得注意的是,Google Cloud Pub/Sub客户端库的版本0.24.0已经存在三年了;现在是版本1.5.0。这个依赖问题(以及许多其他问题)可能已经在某个地方得到了修复,因此可能值得更新到更新的版本。
发布于 2020-10-21 20:04:55
如果你看一下grpcio的可下载文件,你会发现这里有预编译的二进制轮子:
https://pypi.org/project/grpcio/#files
那么,为什么这个构建要从头开始编译呢?因为你在用阿尔卑斯山。高山不支持二进制轮子(更详细的解释请参见https://pythonspeed.com/articles/alpine-docker-python/ )。
正如其他人所说,你可以安装一个编译器...或者,您可以停止使用基于高山的Docker镜像,然后您将能够使用预编译的轮子,并且您的构建速度将会更快。而且你的镜像也会更小,因为你不需要安装编译器(你可以通过多阶段的构建来使阿尔卑斯山的镜像更小,但这需要更多的工作)。
https://stackoverflow.com/questions/62260186
复制相似问题