将Google AnalyticsAPI库添加到Google App Engine

时间:2022-08-16 15:14:27

I am trying to run a simple python script on Google App Engine. How do I install the Google Analytics API library?

我想在Google App Engine上运行一个简单的python脚本。如何安装Google AnalyticsAPI库?

Library: https://developers.google.com/api-client-library/python/apis/analytics/v3

Instructions: https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring

I've tried everything and can't get this to run, even though it works on my pc. What I have right now is: The python scripts in the root folder, In the /lib folder I copied the folders that were installed from my PC (/googleapiclient and /google_api_python_client-1.4.0-py2.7.egg-info) And I have appengine_config.py in /lib folder which contains:

我已经尝试了所有的东西,并且不能让它运行,即使它在我的电脑上运行。我现在拥有的是:根文件夹中的python脚本,在/ lib文件夹中我复制了从我的PC安装的文件夹(/ googleapiclient和/google_api_python_client-1.4.0-py2.7.egg-info)和我在/ lib文件夹中有appengine_config.py,其中包含:

from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder.
vendor.add('lib')
vendor.add('google-api-client')

app.yaml file:

application: psyched-cab-861
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: hello_analytics_api_v3.app

Traceback:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
ImportError: No module named helloworld

New Log:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 354, in __getattr__
    self._update_configs()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 290, in _update_configs
    self._registry.initialize()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
    import_func(self._modname)
  File "/base/data/home/apps/s~just-*-94303/1.384249106864280829/appengine_config.py", line 5, in <module>
    vendor.add('google-api-python-client')
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
    'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access google-api-python-client: No such virtualenv or site directory

I tried editing the appengine_config.py file to

我尝试将appengine_config.py文件编辑为

vendor.add('googleapiclient')  #The name of the file

I edit it in GAE, and click commit, it saves, but I get the same error as above with the vendor.add('google-api-python-client') error. Why is the file not updating?

我在GAE中编辑它,然后单击提交,它保存,但我得到与上面相同的错误与vendor.add('google-api-python-client')错误。为什么文件没有更新?

1 个解决方案

#1


As the docs say: put the appengine_config.py in your root folder of the application (and not in the /lib folder). By the way, the name of the library is google-api-python-client and not google-api-client.

正如文档所说:将appengine_config.py放在应用程序的根文件夹中(而不是在/ lib文件夹中)。顺便说一句,该库的名称是google-api-python-client而不是google-api-client。

Then you have to install google-python-api-client in your /lib folder:

然后你必须在/ lib文件夹中安装google-python-api-client:

$ pip install -t lib google-api-python-client

#1


As the docs say: put the appengine_config.py in your root folder of the application (and not in the /lib folder). By the way, the name of the library is google-api-python-client and not google-api-client.

正如文档所说:将appengine_config.py放在应用程序的根文件夹中(而不是在/ lib文件夹中)。顺便说一句,该库的名称是google-api-python-client而不是google-api-client。

Then you have to install google-python-api-client in your /lib folder:

然后你必须在/ lib文件夹中安装google-python-api-client:

$ pip install -t lib google-api-python-client