0

I'm using Google Cloud AppEngine based on the examples provided on Github I was testing the blobstore example but when I try to include the API google.cloud.speech in that example I get the error "No module named google.cloud.speech" but in the speech demo the same import it works.

dev_appserver.py app.yaml

In the speech demo when I include the import google.appengine.api I have the error No module named appengine.api, but the same import it works on the blobstore example.

python2.7 transcribeSpeech.py resources/audio.raw

First Error

ERROR    2018-01-17 12:07:09,600 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/user/src/project/python_gae_quickstart_editor-2018-01-14-21-40/appengine/standard/blobstore/gcs/main.py", line 13, in <module>
    from google.cloud import speech
  File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1147, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named google.cloud.speech

Second error:

Traceback (most recent call last):
  File "transcribeSpeech.py", line 39, in <module>
    import cloudstorage
  File "/home/user/src/project/python_gae_quickstart_editor-2018-01-14-21-40/appengine/standard/blobstore/gcs/lib/cloudstorage/__init__.py", line 20, in <module>
    from .api_utils import RetryParams
  File "/home/user/src/project/python_gae_quickstart_editor-2018-01-14-21-40/appengine/standard/blobstore/gcs/lib/cloudstorage/api_utils.py", line 45, in <module>
    from google.appengine.api import app_identity
ImportError: No module named appengine.apiv
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
COROSCOP
  • 21
  • 5

1 Answers1

0

You're mixing up standard env GAE apps (your 1st invocation) with standalone python apps (your 2nd invocation) - not the same thing, they don't work the same way, so don't make behaviour comparisons between them expecting to be the same/similar. See GAE works but import webapp2 failed in Spyder.

If your app is a GAE standard app (the only ones supported by dev_appserver.py) then you have to vendor in all additional libraries inside your app (GAE doesn't know/care about libraries installed in your virtual env or your local python installation). See python google app engine stripe integration.

Each of the (standard env GAE) examples you're following contains a requirements.txt with the required libraries - that's the library you need to vendor in, don't just dump the entire example directory in your app and expect the examples to work (as the filepaths in your tracebacks appear to suggest). They're just independent snippets/examples, not a fully functional, ready-to-use app as a whole. See instructions at https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • also potentially of interest: https://stackoverflow.com/questions/45842772/how-to-tell-if-a-google-app-engine-documentation-page-applies-to-the-standard-or – Dan Cornilescu Jan 17 '18 at 16:01
  • Thank you for you help, I followed this steps: Added to requirements.txt the library google-cloud-speech=0.30.0 Then pip install -t lib/ -r requirementes.txt In the appengine_config.py `code`from google.appengine.ext import vendor # Add any libraries installed in the "lib" folder. vendor.add('lib') `code` And still get the error ImportError: No module named google.cloud.speech but the library is in the lib directory and the path is inside sys.path I also try with the google-api-python-client with no success. Thanks – COROSCOP Jan 17 '18 at 23:07
  • I can't repro, `from google.cloud import speech` works for me, however it seems the library uses the `mp` library and hits this issue: https://github.com/googleapis/gax-python/issues/149, so you might not be able to use it on GAE. – Dan Cornilescu Jan 18 '18 at 05:35