【问题标题】:Deploying an app on Google App Engine - Error from requirements.txt在 Google App Engine 上部署应用程序 - requirements.txt 中的错误
【发布时间】:2020-02-02 11:12:16
【问题描述】:

我无法在 Google App Engine 上部署应用程序。

问题似乎来自我的requirements.txt 文件:

  • 当我部署示例 building-an-app-1 时,它运行良好。
  • 当我用我的替换原始 requirements.txt 文件时,它不起作用*。

这是我的requirements.txt

Flask==1.1.1
flask-wtf==0.14.2
unidecode
numpy
openfoodfacts
os

当我删除最后两个包时,它可以工作。

有什么问题?

*gcloud deploy app 返回:

File upload done.
Updating service [default]...failed.                                           
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build 813ab290-60a1-427c-830f-3a7e2d35f39b status: FAILURE.
Build error details: {"error":{"errorType":"BuildError","canonicalCode":"INVALID_ARGUMENT","errorId":"288DA415","errorMessage":"01 Feb 2020 17:23:53 INFO     Arguments: ['--parser_script=/usr/local/bin/ftl.par', '--src=', '--entrypoint=', '--name=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/app/ttl-2h:34df8d6c-74e5-4583-bd94-165295531608', '--directory=/workspace', '--destination=/srv', '--cache-repository=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/build-cache/ttl-7d', '--cache', '--builder-output-path=\"\"', '--additional-directory=/.googleconfig', '--python-cmd=/opt/python3.7/bin/python3.7', '--pip-cmd=/env/bin/python3.7 -m pip', '--venv-cmd=/opt/python3.7/bin/python3.7 -m venv /env', '-v=DEBUG', '--base=eu.gcr.io/gae-runtimes/python37:python37_20191019_3_7_4_RC00']
01 Feb 2020 17:23:53 INFO     Unparsed arguments: ['--name=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/app/ttl-2h:34df8d6c-74e5-4583-bd94-165295531608', '--directory=/workspace', '--destination=/srv', '--cache-repository=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/build-cache/ttl-7d', '--cache', '--builder-output-path=\"\"', '--additional-directory=/.googleconfig', '--python-cmd=/opt/python3.7/bin/python3.7', '--pip-cmd=/env/bin/python3.7 -m pip', '--venv-cmd=/opt/python3.7/bin/python3.7 -m venv /env', '-v=DEBUG', '--base=eu.gcr.io/gae-runtimes/python37:python37_20191019_3_7_4_RC00']
01 Feb 2020 17:23:53 INFO     Executing ['/usr/local/bin/ftl.par', '--name=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/app/ttl-2h:34df8d6c-74e5-4583-bd94-165295531608', '--directory=/workspace', '--destination=/srv', '--cache-repository=eu.gcr.io/skilful-alpha-259713/app-engine-tmp/build-cache/ttl-7d', '--cache', '--builder-output-path=\"\"', '--additional-directory=/.googleconfig', '--python-cmd=/opt/python3.7/bin/python3.7', '--pip-cmd=/env/bin/python3.7 -m pip', '--venv-cmd=/opt/python3.7/bin/python3.7 -m venv /env', '-v=DEBUG', '--base=eu.gcr.io/gae-runtimes/python37:python37_20191019_3_7_4_RC00']
INFO     FTL version python-v0.17.0
INFO     Beginning FTL build for python
INFO     FTL arg passed: virtualenv_dir /env
INFO     FTL arg passed: ttl 168
INFO     FTL arg passed: python_cmd /opt/python3.7/bin/python3.7
INFO     FTL arg passed: cache True
INFO     FTL arg passed: virtualenv_cmd virtualenv
INFO     FTL arg passed: entrypoint None
INFO     FTL arg passed: exposed_ports None
INFO     FTL arg passed: pip_cmd /env/bin/python3.7 -m pip
INFO     FTL arg passed: tar_base_image_path None
INFO     FTL arg passed: export_cache_stats False
INFO     FTL arg passed: builder_output_path \"\"
INFO     FTL arg passed: destination_path /srv
INFO     FTL arg passed: sh_c_prefix False
INFO     FTL arg passed: base eu.gcr.io/gae-runtimes/python37:python37_20191019_3_7_4_RC00
INFO     FTL arg passed: cache_key_version v0.17.0
INFO     FTL arg passed: cache_salt 
INFO     FTL arg passed: cache_repository eu.gcr.io/skilful-alpha-259713/app-engine-tmp/build-cache/ttl-7d
INFO     FTL arg passed: venv_cmd /opt/python3.7/bin/python3.7 -m venv /env
INFO     FTL arg passed: name eu.gcr.io/skilful-alpha-259713/app-engine-tmp/app/ttl-2h:34df8d6c-74e5-4583-bd94-165295531608
INFO     FTL arg passed: global_cache False
INFO     FTL arg passed: upload True
INFO     FTL arg passed: fail_on_error True
INFO     FTL arg passed: output_path None
INFO     FTL arg passed: directory /workspace
INFO     FTL arg passed: additional_directory /.googleconfig
INFO     FTL arg passed: verbosity DEBUG
INFO     starting: full build
INFO     starting: builder initialization
INFO     Loading Docker credentials for repository 'eu.gcr.io/gae-runtimes/python37:python37_20191019_3_7_4_RC00'
INFO     Loading Docker credentials for repository 'eu.gcr.io/skilful-alpha-259713/app-engine-tmp/app/ttl-2h:34df8d6c-74e5-4583-bd94-165295531608'
INFO     builder initialization took 0 seconds
INFO     starting: build process for FTL image
INFO     starting: checking_cached_interpreter_layer
INFO     starting: check python version
INFO     `python version` full cmd:
/opt/python3.7/bin/python3.7 --version
I.

【问题讨论】:

    标签: python google-app-engine google-cloud-platform


    【解决方案1】:

    根据您收到的错误,Cloud Build 未能安装您在 requirements.txt 文件中指定的最后两个依赖项。如果您转到 Cloud Build History page 并检查失败的部署,您会注意到部署失败并显示与此类似的错误消息:

    Step #1 - "builder": INFO     `pip_download_wheels` had stderr output:
    Step #1 - "builder":   Could not find a version that satisfies the requirement openfoodfacts==0.1.0 (from -r requirements.txt (line 10)) (from versions: )
    Step #1 - "builder": No matching distribution found for openfoodfacts==0.1.0 (from -r requirements.txt (line 10))
    

    没有必要在 requirements.txt 中包含os module,因为它是 Python 3.7 标准库的一部分。请注意,例如,您的应用程序所基于的main.py 会导入datetime module,而requirements.txt file 上没有指定。

    Open Food Facts package 实际上并没有在 PyPI 上发布(即,https://pypi.org/project/openfoodfacts/ 是 404)所以你需要参考App Engine's documentation 的相关部分并手动添加它,以与此类似的方式:

    1. 在应用程序的项目目录中创建一个lib 目录(例如,我使用mkdir lib)。
    2. 通过发出以下命令将所需的依赖项复制到新创建的lib 目录:pip3 install git+git://github.com/openfoodfacts/openfoodfacts-python.git -t lib
    3. 转到lib 目录并验证是否已正确安装所有依赖项。
    4. 修改您的 requirements.txt 文件以使用 Open Food Facts 包所需的依赖项。它应该如下所示:
    Flask==1.1.1
    flask-wtf==0.14.2
    unidecode==1.1.1
    numpy==1.18.1
    certifi==2019.11.28
    chardet==3.0.4
    idna==2.8
    requests==2.22.0
    urllib3==1.25.8
    
    1. 以与import lib.openfoodfacts as openff 类似的方式在您的应用中导入模块。
    2. 使用gcloud app deploy 命令部署您的应用程序。

    最后你应该有一个与这个文件结构相似的项目目录:

    building-an-app-1/
        app.yaml
        lib/
            ...
            openfoodfacts/
                autosuggest.py
                facets.py
                __init__.py
                openbeautyfacts.py
                openpetfoodfacts.py
                products.py
                __pycache__/
                utils.py
            ...
        main.py
        requirements.txt
        static/
            script.js
            style.css
        templates/
            index.html
    

    您可以使用以下命令在main.py 文件中导入osopenfoodfacts 模块:

    ...
    import datetime
    import os
    import lib.openfoodfacts as openff
    from flask import Flask, render_template
    app = Flask(__name__)
    @app.route('/')
    ....
    

    【讨论】:

      【解决方案2】:

      您是否尝试过像这样在本地使用这个 requirements.txt 文件?:

      pip install -r requirements.txt
      

      您的 requirements.txt 文件的最后两行似乎与可以使用 pip 安装的 Python 包不对应。

      【讨论】:

        【解决方案3】:

        确实,requirements.txt 文件中同时存在 osopenfoodfacts(该文件只需要包含可安装 pip 的软件包,请参阅 Declaring and managing dependencies)导致 pip 安装错误:

        [venv] openfoodfacts> pip install os
        Collecting os
          Could not find a version that satisfies the requirement os (from versions: )
        No matching distribution found for os
        
        [venv] openfoodfacts> pip install openfoodfacts
        Collecting openfoodfacts
          Could not find a version that satisfies the requirement openfoodfacts (from versions: )
        No matching distribution found for openfoodfacts
        

        您不需要将os 添加到您的要求中,它是标准python 安装的一部分,您只需导入即可。

        而且openfoodfacts 似乎不是常规的Pypi 包。如果它来自不需要 SSH 密钥的 pip 存储库,您可以在 requirements.txt 文件中指定它,请参阅 How to add a package-specific index-url to requirements.txt?。否则,您需要将其安装在您的应用中,以便与您的应用代码一起上传,请查看Private dependencies 部分。

        您可以/应该始终尝试使用install your dependencies locally 作为requirements.txt 文件的健全性检查。请注意需要 SSH 密钥的 pip 存储库,因为您可以通过您的帐户配置默认访问这些密钥。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-04-22
          • 1970-01-01
          • 1970-01-01
          • 2019-05-18
          • 1970-01-01
          • 2011-07-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多