0

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
bossylobster
  • 9,993
  • 1
  • 42
  • 61
Analytics360
  • 31
  • 1
  • 8
  • Did you ever install via the requirements file? e.g. `pip install -t lib -r requirements.txt` ? – GAEfan Sep 16 '16 at 21:43
  • @GAEfan I get the same error even after installing the requirements file using pip command as mention by you earlier. – Analytics360 Sep 19 '16 at 15:19
  • Too many possibilities. What does your file tree look like? Is gcloud in your sys.path? Remove `target:main` from cron, as that is not correct. – GAEfan Sep 19 '16 at 15:48
  • `gcloud` needs to be vendored in into your app: https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library – Dan Cornilescu Sep 20 '16 at 18:25
  • Also in your `app.yaml` your should theoretically have `script: main.app` instead of `script: main` (from the traceback it seems GAE figured it out even without that, but personally I wouldn't rely on it). – Dan Cornilescu Sep 20 '16 at 18:28
  • **Trace back after adding appengine_config.py to vendor lib that contains gcloud** \ ' File "/base/data/home/apps/s~myapp/my-cron:20161026t102827.396611273014256461/appengine_config.py", line 7, in from google.appengint.ext import vendor ImportError: No module named appengint.ext' – Analytics360 Oct 26 '16 at 20:29

2 Answers2

1

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 .
afed
  • 519
  • 2
  • 6
  • While this *might* work it is not actually aligned with the recommended 3rd party installation procedure: https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library – Dan Cornilescu Sep 27 '16 at 04:00
1

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

Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
Analytics360
  • 31
  • 1
  • 8