0

I'm getting a ContextualVersionConflict when making a call to Google Cloud Vision API

I have installed/upgraded the libraries I can think of, to no avail. The code works on my local machine, the issue just happens in Datalab.

Code:

!pip install --upgrade google-cloud-bigquery
!pip install --upgrade google-api-python-client
!pip install --upgrade google-api-core
!pip install --upgrade google-cloud-vision

#below from https://cloud.google.com/vision/docs/detecting-safe-search
def detect_safe_search_uri(uri):
    """Detects unsafe features in the file located in Google Cloud Storage or
    on the Web."""
    from google.cloud import vision
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri

    response = client.safe_search_detection(image=image)
    safe = response.safe_search_annotation

    # Names of likelihood from google.cloud.vision.enums
    likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE',
                       'LIKELY', 'VERY_LIKELY')
    print('Safe search:')

    print('adult: {}'.format(likelihood_name[safe.adult]))
    print('medical: {}'.format(likelihood_name[safe.medical]))
    print('spoofed: {}'.format(likelihood_name[safe.spoof]))
    print('violence: {}'.format(likelihood_name[safe.violence]))
    print('racy: {}'.format(likelihood_name[safe.racy]))

#Sample URI    
detect_safe_search_uri("https://www.victoriassecret.com/p/404x539/tif/1a/d2/1ad2f0b4a7054d81ad178b941f3a8b80/395481036_OM_F.jpg")

Error:

...
...
...

/usr/local/envs/py3env/lib/python3.5/site-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    784                 # Oops, the "best" so far conflicts with a dependency
    785                 dependent_req = required_by[req]
--> 786                 raise VersionConflict(dist, req).with_context(dependent_req)
    787 
    788             # push the new requirements onto the stack

ContextualVersionConflict: (google-api-core 0.1.4 (/usr/local/envs/py3env/lib/python3.5/site-packages), Requirement.parse('google-api-core[grpc]<2.0.0dev,>=1.6.0'), {'google-cloud-vision'})
Jose
  • 13
  • 1
  • 3

1 Answers1

1

You would have to specify a different version than default one for your google-cloud-vision library (for some reason it doesn't work with the latest one)

!pip install google-cloud-vision==0.29.0

import google.datalab.storage as storage
import google.datalab.utils as utils
from io import BytesIO

from google.cloud import vision
from google.cloud.vision import types
from PIL import Image, ImageDraw
Kris
  • 5,714
  • 2
  • 27
  • 47