运行 本地使用 GAE Python 第二代

Running locally with GAE Python second generation

多年来我一直在使用 GAE/P 第一代,现在正在跳转到我的第一个 GAE/P 第二代项目。

我正尝试在本地 运行 它就像我对第一代应用程序 dev_appserver.py 所做的那样,但是 the docs 在这方面非常混乱。

我可以 运行 Flask 单独使用 (python main.py) 但静态文件不起作用(因为 Flask 对 app.yaml 一无所知)并且数据存储也不起作用.

GAE 文档说 dev_appserver.py 应该适用于第二代(Windows 除外,但我在 Mac)但是当我 运行 它时,我得到下面的错误。

当我 运行 dev_appserver.py 和 Python 2 或 3 时会发生这种情况。我还按照说明将 CLOUDSDK_PYTHON 设置为我的 Python 2 二进制文件.

那么我怎么才能 运行 我的 GAE/P 第二代项目在本地以静态文件和数据存储区工作的方式?!?


$ python ~/google-cloud-sdk/bin/dev_appserver.py --application=myapp --support_datastore_emulator=False ./app.yaml 
INFO     2019-02-12 00:39:21,885 devappserver2.py:278] Skipping SDK update check.
INFO     2019-02-12 00:39:23,128 api_server.py:275] Starting API server at: http://localhost:51187
INFO     2019-02-12 00:39:23,139 instance_factory.py:71] Detected Python 3.6.5

INFO     2019-02-12 00:39:24,459 instance_factory.py:205] Using pip to install dependency libraries; pip stdout is redirected to /var/folders/yd/xr84fg0946l72fp_cc6j9l540000gr/T/tmpj3SEUZ
INFO     2019-02-12 00:39:24,459 instance_factory.py:211] Running /var/folders/yd/xr84fg0946l72fp_cc6j9l540000gr/T/tmpLtysT3/bin/pip install --upgrade pip
INFO     2019-02-12 00:39:24,469 stub_util.py:357] Applying all pending transactions and saving the datastore
INFO     2019-02-12 00:39:24,469 stub_util.py:360] Saving search indexes
Traceback (most recent call last):
  File "/.../google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 96, in <module>
    _run_file(__file__, globals())
  File "/.../google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 90, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 600, in <module>
    main()
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 588, in main
    dev_server.start(options)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 360, in start
    options.api_host, apiserver.port, wsgi_request_info_)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 248, in start
    ssl_port)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 384, in _create_module
    ssl_port=ssl_port)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1309, in __init__
    super(AutoScalingModule, self).__init__(**kwargs)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 598, in __init__
    self._module_configuration)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 231, in _create_instance_factory
    module_configuration=module_configuration)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 98, in __init__
    self._SetupVirtualenvFromConfiguration()
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 143, in _SetupVirtualenvFromConfiguration
    self._venv_dir, requirements_file.name)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 228, in _SetupVirtualenv
    cls._RunPipInstall(venv_dir, requirements_file_name)
  File "/.../google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/instance_factory.py", line 212, in _RunPipInstall
    pip_proc = subprocess.Popen(pip_cmd, stdout=pip_out)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

睡了一觉后,我终于找到问题了...

我 运行 dev_appserver.py 来自我的虚拟环境。出于某种原因,这导致 dev_appserver.py 无法找到 pip(需要在我的 requirements.txt 中安装软件包)。

在 运行 dev_appserver.py 解决问题之前退出我的虚拟环境。