2

设置:在 Google Cloud Shell 标准环境中运行

我尝试使用从烧瓶应用程序访问firestorefrom google.cloud import firestore

我已经使用pip install --upgrade google-cloud-firestore -t lib. 如果我手动运行脚本,它工作正常。但是在使用时dev_appserver.py,它失败了。得到下面的错误。

$ dev_appserver.py app.yaml
INFO     2017-10-06 07:34:35,301 devappserver2.py:105] Skipping SDK update check.
INFO     2017-10-06 07:34:35,391 api_server.py:300] Starting API server at: http://0.0.0.0:34796
WARNING  2017-10-06 07:34:35,391 dispatcher.py:312] Your python27 micro version is below 2.7.12, our current production version.
INFO     2017-10-06 07:34:35,440 dispatcher.py:251] Starting module "default" running at: http://0.0.0.0:8080
INFO     2017-10-06 07:34:35,441 admin_server.py:116] Starting admin server at: http://0.0.0.0:8000

ERROR    2017-10-06 07:34:42,266 wsgi.py:263]
Traceback (most recent call last):
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/user1/projects/probfe/main.py", line 10, in <module>
    from google.cloud import firestore
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1132, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named google.gax

但是,在我的 中lib,我可以看到它们。

$ls lib
builtins                       future-0.16.0.dist-info                         itsdangerous.pyc                requests-2.18.4.dist-info
cachetools                     futures-3.1.1.dist-info                         jinja2                          rsa
cachetools-2.0.1.dist-info     google                                          Jinja2-2.9.6.dist-info          rsa-3.4.2.dist-info
certifi                        googleapis_common_protos-1.5.3.dist-info        libfuturize                     setuptools
certifi-2017.7.27.1.dist-info  googleapis_common_protos-1.5.3-py2.7-nspkg.pth  libpasteurize                   setuptools-36.5.0.dist-info
chardet                        google_auth-1.1.1.dist-info                     _markupbase                     six-1.11.0.dist-info
chardet-3.0.4.dist-info        google_auth-1.1.1-py2.7-nspkg.pth               markupsafe                      six.py
click                          google_cloud_core-0.27.1.dist-info              MarkupSafe-1.0.dist-info        six.pyc
click-6.7.dist-info            google_cloud_core-0.27.1-py3.6-nspkg.pth        past                            socketserver
concurrent                     google_cloud_firestore-0.27.0.dist-info         pkg_resources                   tests
copyreg                        google_cloud_firestore-0.27.0-py3.6-nspkg.pth   ply                             _thread
dill                           google_gax-0.15.15.dist-info                    ply-3.8.dist-info               tkinter
dill-0.2.7.1.dist-info         google_gax-0.15.15-py2.7-nspkg.pth              protobuf-3.4.0.dist-info        urllib3
_dummy_thread                  grpc                                            protobuf-3.4.0-py2.7-nspkg.pth  urllib3-1.22.dist-info
easy_install.py                grpcio-1.4.0.dist-info                          pyasn1                          werkzeug
easy_install.pyc               html                                            pyasn1-0.3.7.dist-info          Werkzeug-0.12.2.dist-info
enum                           http                                            pyasn1_modules                  winreg
enum34-1.1.6.dist-info         idna                                            pyasn1_modules-0.1.4.dist-info  xmlrpc
flask                          idna-2.6.dist-info                              queue
Flask-0.12.2.dist-info         itsdangerous-0.24.dist-info                     reprlib
future                         itsdangerous.py                                 requests
4

1 回答 1

0

由于您使用dev_appserver.py它意味着您有一个标准的环境应用程序。在标准环境中,所有外部依赖项都需要安装在您的应用程序中,而不是在本地 python 安装中(这是您对pip调用所做的)。

安装第三方库

  1. 创建一个目录来存储您的第三方库,例如lib/.

    mkdir lib
    
  2. 使用带有标志的pip(版本 6 或更高版本)-t <directory>将库复制到您在上一步中创建的文件夹中。例如:

    pip install -t lib/ <library_name>
    
于 2017-10-06T16:46:57.493 回答