如何修复“无法构建应用程序。错误:无法流式传输生成输出:命令“/bin/sh -c pip install --no-cache-dir -r requirements.txt”

How to fix "Failed to build the app . Error: unable to stream build output: The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt"

提问人:XEOX 提问时间:2/23/2022 最后编辑:XEOX 更新时间:2/23/2022 访问量:485

问:

我是gcloud的新手,我不知道如何修复这个错误:(

当我尝试将我的 API 部署到 Cloud 运行时,我收到以下错误消息:

Failed to build the app. Error: unable to stream build output: The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1 

以下是详细日志:

[0m
[91mWARNING: You are using pip version 21.2.4; however, version 22.0.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
[0m
unable to stream build output: The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1
Failed to build the app. Error: unable to stream build output: The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1

这是我尝试在第一个文件(snsr.py)中导入的内容:

import requests
import numpy
import time
from time import sleep
import re
import random 
import math
import hashlib
from urllib.parse import unquote

这是我尝试在第二个文件(main.py)中导入的内容:

from flask import Flask, jsonify, request
import snsr
import os 
import binascii
import hashlib

这是我requirements.txt文件:

Flask==2.0.2
gunicorn==20.1.0
requests
numpy
regex
python-math
urllib3
os-win

这是我的docker:

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.10-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install -r requirements.txt

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
google-cloud-platform gcloud google-cloud-error-reporting

评论

0赞 Chris32 2/23/2022
看起来 docker 中的 pip 已过时,请尝试将此命令添加到 docker 中,然后再安装要求“RUN pip install -U --upgrade pip”
0赞 DazWilkin 2/23/2022
pip 升级消息是一个警告,可以忽略。返回代码是问题所在,这是由以下原因引起的:由于您的要求很简单,我认为这是您的要求之一的结果。non-zeropip install -r requirements.txtDockerfile
0赞 DazWilkin 2/23/2022
如果在本地安装了 OR(或其他)容器,则一个方便的诊断方法是尝试在本地构建容器 ( 并查看出现什么错误。容器的一个优点是,如果它(不)在一个地方构建,它(不应该)在任何地方构建。dockerpodmandocker build --tag=deleteme --file=./Dockerfile .
1赞 DazWilkin 2/23/2022
我的猜测(!)是 os-win 是问题所在。
0赞 John Hanley 2/23/2022
OpenStack 和 Cloud Run 是不同的服务。Cloud Run 不基于 Windows 或 Hyper-V。您有多个问题。首先在本地构建容器并在 Linux 环境中运行。删除 Windows Hyper-V 要求。将 gunicorn 配置为侦听正确的 Cloud Run 端口(默认为 8080)。

答: 暂无答案