我无法在Google App Engine上部署应用。
问题似乎来自我的requirements.txt
文件:
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.
答案 0 :(得分:2)
根据您收到的错误,Cloud Build无法安装您在requirements.txt文件中指定的最后两个依赖项。如果您转到Cloud Build History page并检查失败的部署,则会注意到部署失败,并显示与此类似的错误消息:
inline Scalar& operator()(double r, double c) {
// double r_offset = -0.5, c_offset = -0.5;
return Base::operator()(int(r - r_offset), int(c - c_offset));
}
由于它是Python 3.7标准库的一部分,因此不需要在{.3。}中包含os module。例如,请注意,您基于应用程序的main.py会导入datetime module,而在requirements.txt file上未指定。
Open Food Facts package实际上尚未在PyPI上发布(即https://pypi.org/project/openfoodfacts/为404),因此您需要参考App Engine's documentation的相关部分并手动添加,与此类似:
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))
目录(例如,我使用lib
)。mkdir lib
,将所需的依赖项复制到新创建的lib
目录中。pip3 install git+git://github.com/openfoodfacts/openfoodfacts-python.git -t lib
目录并验证是否已正确安装所有依赖项。 lib
文件以使用Open Food Facts软件包所需的依赖项。它应该看起来像这样:requirements.txt
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
的方式将模块导入您的应用程序。import lib.openfoodfacts as openff
命令来部署您的应用程序。最后,您应该有一个项目目录,其文件结构与此目录相似:
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
文件上导入os
和openfoodfacts
模块:
main.py
答案 1 :(得分:0)
您是否尝试像这样在本地使用此requirements.txt文件?:
pip install -r requirements.txt
您的requirements.txt文件的最后两行似乎与可以通过pip安装的Python软件包不符。
答案 2 :(得分:0)
实际上,os
文件中同时存在openfoodfacts
和requirements.txt
(该文件仅需要可通过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回购协议,因为默认情况下,您可以通过帐户配置访问这些密钥。
答案 3 :(得分:0)
现在,我无法部署要求为pyzbar==0.1.8
(已在PyPi上发布)的应用。
我遇到以下错误:
Traceback (most recent call last): File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process super().init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/srv/main.py", line 21, in <module> from forms import BarcodeForm
File "/srv/forms.py", line 1, in <module> from flask_wtf import FlaskForm
File "/env/lib/python3.7/site-packages/flask_wtf/__init__.py", line 17, in <module> from .recaptcha import *
File "/env/lib/python3.7/site-packages/flask_wtf/recaptcha/__init__.py", line 2, in <module> from .fields import *
File "/env/lib/python3.7/site-packages/flask_wtf/recaptcha/fields.py", line 3, in <module> from . import widgets File "/env/lib/python3.7/site-packages/flask_wtf/recaptcha/widgets.py", line 5, in <module> from werkzeug import url_encode ImportError: cannot import name 'url_encode' from 'werkzeug' (/env/lib/python3.7/site-packages/werkzeug/__init__.py)
你知道发生了什么吗?