将Flask应用程序部署到Google Cloud Platform时无法获得正确的TensorFlow版本

如何解决将Flask应用程序部署到Google Cloud Platform时无法获得正确的TensorFlow版本

我正在尝试将Python Flask应用程序部署到Google Cloud Platform(App Engine)。该应用程序在我的计算机上可以在本地正常运行。我在我的应用程序中使用Tensorflow版本2.3.0。当我尝试将应用程序部署到Google Cloud Platform时,这似乎是一个问题。尝试构建应用程序时,我在构建日志中收到以下错误代码:

Collecting tensorflow==2.3.0 (from -r requirements.txt (line 2))
Step #1:   Could not find a version that satisfies the requirement tensorflow==2.3.0 (from -r requirements.txt (line 2)) (from versions: 0.12.1,1.0.0,1.0.1,1.1.0rc0,1.1.0rc1,1.1.0rc2,1.1.0,1.2.0rc0,1.2.0rc1,1.2.0rc2,1.2.0,1.2.1,1.3.0rc0,1.3.0rc1,1.3.0rc2,1.3.0,1.4.0rc0,1.4.0rc1,1.4.0,1.4.1,1.5.0rc0,1.5.0rc1,1.5.0,1.5.1,1.6.0rc0,1.6.0rc1,1.6.0,1.7.0rc0,1.7.0r
c1,1.7.0,1.7.1,1.8.0rc0,1.8.0rc1,1.8.0,1.9.0rc0,1.9.0rc1,1.9.0rc2,1.9.0,1.10.0rc0,1.10.0rc1,1.10.0,1.10.1,1.11.0rc0,1.11.0rc1,1.11.0rc2,1.11.0,1.12.0rc0,1.12.0rc1,1.12.0rc2,1.12.0,1.12.2,1.12.3,1.13.0rc0,1.13.0rc1,1.13.0rc2,1.13.1,1.13.2,1.14.0rc0,1.14.0rc1,1.14.0,2.0.0a0,2.0.0b0,2.0.0b1)
Step #1: No matching distribution found for tensorflow==2.3.0 (from -r requirements.txt (line 2))
Step #1: You are using pip version 10.0.1,however version 20.2.3 is available.
Step #1: You should consider upgrading via the 'pip insll --upgrade pip' command.
Step #1: The command '/bin/sh -c pip install -r requirements.txt' returned a tanon-zero code: 1
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker@sha256:c1128bf8a32cfe4f2efcb920551a71a43d3401d3a3631f8b745e90b75099b68e" failed: step exited with non-zero status: 1
Step #1: 

在构建日志中,我得到以下信息:

Step 3/9 : RUN virtualenv --no-download /env -p python3.6
Step #1:  ---> Running in cd3673a277e1
Step #1: Running virtualenv with interpreter /opt/python3.6/bin/python3.6
Step #1: Using base prefix '/opt/python3.6'
Step #1: New python executable in /env/bin/python3.6
Step #1: Also creating executable in /env/bin/python
Step #1: Installing setuptools,pip,wheel...done.
Step #1: Removing intermediate container cd3673a277e1

如您所见,该应用程序使用Python 3.6环境。如何指定要在Python 3.7或3.8环境中构建我的App?

我的需求文件如下:

pip==20.2.3
tensorflow==2.3.0
Flask==0.11.1
gunicorn==19.5.0
numpy==1.17.4
scipy==1.4.1
h5py==2.10.0

我的YAML文件如下:

entrypoint: "gunicorn -b:$PORT main:app"
env: flex
runtime: python
runtime_config: 
  python_version: 3

从错误代码中,我想问题是:为什么我找不到Tensorflow 2.3.0? 它与旧的python版本或旧的pip版本有关吗?将应用程序部署到Google Cloud Platform时,如何安装更新的pip和Python版本?

我尝试在部署应用程序之前更新Google Cloud Shell中的点。然后我得到了这个警告:

********************************************************************************
Python 2 is deprecated. Upgrade to Python 3 as soon as possible.
See https://cloud.google.com/python/docs/python2-sunset
To suppress this warning,create an empty ~/.cloudshell/no-python-warning file.
The command will automatically proceed in  seconds or on any key.
********************************************************************************
DEPRECATION: Python 2.7 reached the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2
021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /home/bjorn_sing/.local/lib/python2.7/site-packages (20.2.3)
bjorn_sing@cloudshell:~/FlaskApp (my-first-flask-app-289008)$ pip3 install --upgrade pip
Cache entry deserialization failed,entry ignored
Collecting pip
  Using cached https://files.pythonhosted.org/packages/4e/5f/528232275f6509b1fff703c9280e58951a81abe24640905de621c9f81839/pip-20.2.3-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-20.2.3

解决方法

我在自己的环境中重现了您的设置,并显示了与您相同的错误消息,并且据我所知,问题似乎与pip版本有关,可能与Python3.6运行时中的问题有关。

要注意的一件事是,当使用App Engine提供的默认运行时时,配置程度受到限制,这有时会导致跨库版本等的不兼容。例如,App Engine Flexible中的Python运行时仍然不支持Python3.8,而Standard App Engine则支持。

也就是说,与“灵活环境”配合使用的解决方案是通过提供自己的Dockerfile使用custom runtime,在其中您可以指定想要的任何基本映像和运行时。这是我为该用例测试的示例Dockerfile和app.yaml:

# Dockerfile
FROM python:3.8-slim

ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

-------------------

# app.yaml
runtime: custom
env: flex

也就是说,我还必须指出,shakhyar的答案是不正确的。确实可以启用调试模式并通过SSH托管拥有灵活实例的VM,所有所做的更改都是临时的,并且在禁用调试模式后将立即丢失。此外,必须对每个实例都重复此过程,并且在调试模式下必须关闭所有安全补丁程序。因此,连接到实例将无法解决问题。文档here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?