首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Google上部署应用程序-来自requirements.txt的错误

在Google上部署应用程序-来自requirements.txt的错误
EN

Stack Overflow用户
提问于 2020-02-02 11:12:16
回答 3查看 980关注 0票数 0

我不能在上部署应用程序。

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

  • 当我部署示例建筑和应用-1时,它工作得很好。
  • 当我用我的文件替换原始的requirements.txt文件时,它不能工作*。

这是我的requirements.txt

代码语言:javascript
复制
Flask==1.1.1
flask-wtf==0.14.2
unidecode
numpy
openfoodfacts
os

当我移除最后两个包时,它就起作用了。

有什么问题吗?

*gcloud deploy app返回:

代码语言:javascript
复制
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.
EN

回答 3

Stack Overflow用户

发布于 2020-02-02 15:01:04

根据您收到的错误,Cloud未能安装您在requirements.txt文件上指定的最后两个依赖项。如果您转到云构建历史记录页面并检查失败的部署,您会注意到部署失败了,并发出了与此类似的错误消息:

代码语言:javascript
复制
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))

没有必要将os模块包含在requirements.txt上,因为它是Python3.7标准库的一部分。例如,请注意,您的应用程序所来自的main.py导入了日期时间模块,这不是在requirements.txt文件上指定的。

开放式食品包装实际上还没有在PyPI上发布(即https://pypi.org/project/openfoodfacts/是404),因此您需要参考App引擎文档的相关部分并手动添加它,类似于这样:

  1. 在应用程序的Project上创建一个lib目录(例如,我使用mkdir lib)。
  2. 通过发出以下命令将所需的依赖项复制到新创建的lib目录中:pip3 install git+git://github.com/openfoodfacts/openfoodfacts-python.git -t lib
  3. 转到lib目录并验证所有依赖项是否已正确安装。
  4. 修改您的requirements.txt文件以使用Open包所需的依赖项。它应该是这样的:
代码语言:javascript
复制
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命令部署应用程序。

最后,您应该有一个与此文件结构类似的项目目录:

代码语言:javascript
复制
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

在其中,您可以使用以下方法在os文件上导入main.pyopenfoodfacts模块:

代码语言:javascript
复制
...
import datetime
import os
import lib.openfoodfacts as openff
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
....
票数 2
EN

Stack Overflow用户

发布于 2020-02-02 14:54:58

您试过像这样在本地使用这个requirements.txt文件吗?

代码语言:javascript
复制
pip install -r requirements.txt

看起来,requirements.txt文件的最后两行与可以用pip安装的Python不相对应。

票数 0
EN

Stack Overflow用户

发布于 2020-02-02 14:59:42

实际上,osopenfoodfactsrequirements.txt文件中的存在(它只需要包含pip可安装的包,请参阅声明和管理依赖项)会导致pip安装错误:

代码语言:javascript
复制
[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文件中指定它,请参见如何向requirements.txt添加特定于包的索引-url?。否则,您需要在您的应用程序中安装它,以便它可以与您的应用程序代码一起上传,检查私有依赖性部分。

您可以/应该始终尝试将在本地安装依赖项作为对requirements.txt文件的正常检查。注意需要SSH密钥的pip,因为在默认情况下,可以通过您的帐户信任来访问这些密钥。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60025512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档