2

For an application, I have to use Google Vision API. I am able to use from google.cloud import vision and do image analysis in my computer. But, when I deploy my app on developmental server I am getting error:

File "C:\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 34, in <module>
    __version__ = get_distribution('google-cloud-vision').version
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 311, in get_distribution
    if isinstance(dist,Requirement): dist = get_provider(dist)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 197, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
DistributionNotFound: google-cloud-vision

When I create appengine_config.py file that contains:

from google.appengine.ext import vendor
vendor.add('C:\Anaconda2\Lib\site-packages')

I am getting error:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

When I tried the hack mentioned in the link below:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues/1893
https://github.com/googleapis/gax-python/issues/149
https://gist.github.com/nilleb/419122f2f6f1228650dd2dccbd01c5af

I am getting error:

File "C:\Users\MyApp\detect.py", line 11, in <module>
    class DummyProcessing(ModuleType):
NameError: name 'ModuleType' is not defined

Then I followed the instruction here: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#copying_a_third-party_library
And used this command:

pip install -t lib google-cloud-vision==0.28.0

And updated appengine_config.py file:

from google.appengine.ext import vendor
vendor.add('lib')

I am getting error:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

Then I followed the instruction here: Using gcloud-python in GAE

And used this command:

pip install -t vendor google-cloud-vision==0.28.0

I copied appengine_config.py and darth.py files from here: https://github.com/dhermes/test-gcloud-on-gae/tree/8a850fb8b5676ca03e07c4f9dcfba5efb8c77b0a/application

I am getting error:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

I don’t know what to do next. I am completely stuck right now.

Beginner
  • 1,202
  • 2
  • 20
  • 29

1 Answers1

1

The traceback indicates that the library is installed in your local python system (C:\Anaconda2\lib\site-packages\google\cloud\vision) not in the app itself as it should be for a standard env GAE app.

From Google Cloud Vision API Client Library for Python:

App Engine

Because the Python client libraries are not installed in the App Engine Python runtime environment, they must be vendored into your application just like third-party libraries.

From Copying a third-party library:

To use a third-party library that is not on the list of built-in libraries bundled with the runtime:

  • Create a directory to store your third-party libraries, such as lib/.

    mkdir lib
    
  • Use pip (version 6 or later) with the -t <directory> flag to copy the libraries into the folder you created in the previous step. For example:

    pip install -t lib/ <library_name>
    

    ...

Follow the entire vendoring procedure and re-try.

But from the comment on issue 149 you referenced you might have to wait for that issue to be resolved:

@nilleb grpc isn't yet supported on App Engine standard.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Shouldn't matter if you call your app's lib dir `lib` or `vendor` as long as you have the matching config in `appengine_config.py`. But unfortunately my suspicion is confirmed - the blocking problem is really that this version of the vision client library uses gax/multiprocessing, which isn't yet supported in the standard environment. The only thing that comes to mind would be to try an older version, before such support was added (if you can find one). Donno if it makes sense - if you need any capability/fix added since that version probably not. – Dan Cornilescu Nov 24 '17 at 18:45
  • I tried `pip install -t vendor google-cloud-vision==0.24.0`, but I am getting same error. Which version I should try? One more thing, when I am using `appengine_config.py` why it is still looking for `from google.cloud import vision` in `C:\Anaconda2\lib\`? – Beginner Nov 24 '17 at 18:56
  • Not sure which version (I didn't play with that lib yet) - try digging through those issues, maybe you can figure out in which version the gax/multiprocessing was added and pick the previous one. Or blindky try other versions :) II think you may still have `lib` in `appengine_config.py`, which won't match the `vendor` dir. I'd suggest going back to `lib` instead of `vendor` (you can just rename the dir) - it matches the official docs and can help reduce confusion. – Dan Cornilescu Nov 24 '17 at 19:25