I want to use google.cloud library on my Google App Engine python application. In my local all my tests work since I installed this library on my local. I was expecting it to be supported in GAE by default but it's not supported.
This the error I got:
from google.cloud import speech
ImportError: No module named cloud
I had a look at adding 3rd party libraries at https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
After following the instructions I got another error.
(/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:263)
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/main.py", line 18, in <module>
from google.cloud import speech
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/cloud/speech/__init__.py", line 22, in <module>
from google.cloud.speech.client import Client
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/cloud/speech/client.py", line 25, in <module>
from google.cloud.speech._gax import GAPICSpeechAPI
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/cloud/speech/_gax.py", line 17, in <module>
from google.cloud.gapic.speech.v1.speech_client import SpeechClient
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/cloud/gapic/speech/v1/speech_client.py", line 31, in <module>
from google.gapic.longrunning import operations_client
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/gapic/longrunning/operations_client.py", line 45, in <module>
from google.gax import api_callable
File "/base/data/home/apps/s~goooogle-translate/20180126t023051.407206565499030997/lib/google/gax/__init__.py", line 36, in <module>
import multiprocessing as mp
File "/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_dist/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_dist/lib/python2.7/multiprocessing/util.py", line 41, in <module>
from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags
I hardly understand this one. If you have done this before please let me know how to setup google.cloud inside GAE.
As already answered in this other Stack Overflow post about using Client Libraries in App Engine Standard, GAE Standard does not support Google Client Libraries, so you can either go with App Engine Flexible, a Compute Engine instance or work with the REST API (which also has a Python library that works in App Engine Standard).
If you specifically need to use the
google.cloud
library, you will have to use App Engine Flexible and not Standard, but in case you would rather work with the Standard environment, below I share the code for a sample App Engine Standard application using Cloud Speech API through the Google API Python Client Library. This library is not built-in for GAE Standard, so you will have to vendor it as if it was a third-party library. To do so, you will have to create thelib
folder in your local application's directory, and therequirements.txt
file I share below, and then install this library with the commandpip install -t lib/ -r requirements.txt
.Files needed to run this sample GAE Application:
requirements.txt
appengine_config.py
app.yaml
main.py
This application also works in the Local Development Server, so you can test it with the command
dev_appserver.py app.yaml
before deploying it to App Engine.Try this:
sudo pip install --upgrade google-cloud-speech
Or:
I using another library,
Does this method help you up?
Installation:
If you found an error:
Then again:
If you found error try this: