简体   繁体   中英

google-app-engine fails to run Cron job and gives an ImportError: No module named gcloud

app-engine fails to import gcloud used gcloud app deploy app.yaml \\cron.yaml to deploy on google app engine

opened on browser and get:

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])
  File "/base/data/home/apps/s~gcp-project-01/20160916t160552.395688991947248655/main.py", line 18, in <module>
    import update_datastore as ud
  File "/base/data/home/apps/s~vehicle-monitors-api/20160916t160552.395688991947248655/update_datastore.py", line 20, in <module>
    from gcloud import datastore, logging
ImportError: No module named gcloud

The app.yaml file:

    runtime: python27
    api_version: 1
    threadsafe: true

handlers: 
- url: /
  script: main
  login: admin

The cron.yaml file:

 cron:
    - description: run main app
      url: /
      target: main
      schedule: every 2 minutes

the requirements.txt file:

   gcloud==0.14.0

All 3rd party packages need to be installed in the same directory as your app. Run this from the root directory of your application to install it.

pip install gcloud -t .

Got it working! Use path:

import sys
sys.path.insert(0, 'lib')

Additional:
Also need to add protobuf in requirements: protobuf==3.1.0.post1

create __init__.py in google folder:

# this is a namespace package
try:
    import pkg_resources
    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil
    __path__ = pkgutil.extend_path(__path__, __name__)

also use pip install -t lib --upgrade protobuf

gcloud==0.18.1 used.

Sorry for the late post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM