在 app.yml 文件中断应用程序中将 python flask runtime 升级到 37

Upgrading python flask runtime to 37 in app.yml file breaks app

从 google https://cloud.google.com/deployment-manager/docs/migrate-to-python3 收到此消息,我正在尝试将我的 运行 时间更改为 python 3 例如:

    application: myapp
    version: 5
    runtime: python37

   api_version: 1
   threadsafe: true
   default_expiration: 10m

   libraries:
   - name: ssl
   version: "latest"

   handlers:
   - url: .*
   script: run.application
   - url: /static
   static_dir: static
   expiration: 10m

另请注意,我 运行 我的应用程序使用 google 云 SDK 版本 274.0.0,所以我 运行 类似于: dev_appserver app.yml 这是我的错误

    Traceback (most recent call last):
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 96, in <module>
    _run_file(__file__, globals())
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 90, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 608, in <module>
    main()
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 596, in main
    dev_server.start(options)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 273, in start
    env_variables=parsed_env_variables)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 966, in __init__
    env_variables)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 140, in __init__
    self._config_path)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 524, in _parse_configuration
    config, files = appinfo_includes.ParseAndReturnIncludePaths(f)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 82, in ParseAndReturnIncludePaths
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 2672, in LoadSingleAppInfo
    listener.Parse(app_info)
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 242, in Parse
    stream, loader_class, version=version, **loader_args))
  File "/home/chuks/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 180, in _HandleEvents
    raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: libraries entries are only supported by the "python27" runtime
  in "app.yaml", line 35, column 1

通过阅读您的配置文件,我了解到您的应用程序是在标准 App Engine 环境下运行的。如有不妥请指正

引用 documentation,

“The Python 3 runtime on the App Engine standard environment is significantly different from the Python 2 runtime.”

如果您决定在 App Engine 标准环境中将您的应用程序从 Python 2 迁移到 Python 3,您应该注意以下差异:

通过查看有关最后一个项目符号(更改为 app.yaml)的信息,我意识到 app.yaml 配置文件中某些字段的行为已被修改。 “”字段已被弃用,可以使用“requirements.txt[安装任意第三方依赖项=75=]”元数据文件。


能否尝试从 app.yaml 文件中删除“库”部分并重新部署?


编辑:


默认情况下,App Engine 在名为 main.py 的文件中查找应用程序变量。根据 this documentation,运行时通过使用 app.yaml 文件中可选入口点字段的内容来启动您的应用程序。您可以尝试使用您自己的应用程序来配置该入口点,例如:

entrypoint: gunicorn -b :$PORT run.application:main

此外,main.py 必须位于应用程序的根目录中,其中 app.yaml 是。

一般来说,我建议您也将本地系统升级到 Python 3,因为 Python 2.7 will not be maintained past 2020. Subsequently I suggest that you read thoroughly through the documentation about local development and using the local development server


编辑 2:

断言条件是一种调试条件,如果逻辑条件(您在日志消息中看到的)为假,则会抛出异常错误。

发生这种情况是因为根据文档 (link1, link2) 我在之前的编辑中发布,

running dev_appserver requires the presence of Python 2.7.12+ on your local machine and if your OS is Windows the updated dev_appserver does not support development of Python 3 apps.

根据this(此处也描述了一些示例):

To test your application's functionality in your local environment it is recommended that you use standard Python tools, such as virtualenv to create isolated environments and pytest to run unit tests and integration tests rather than depending on dev_appserver, the local development server provided with the Google Cloud SDK.

请仔细阅读文档,以便理解和理解 Python 2 和 Python 3 环境之间关于 App Engine 的差异。