Skip to content

Error while trying to initialize the google vision service #10220

@ghost

Description

Every single time I try to run the following code (python version 3.7):

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

    with io.open(path, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)

    response = client.text_detection(image=image)
    texts = response.text_annotations
    print('Texts:')

    for text in texts:
        print('\n"{}"'.format(text.description))

        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        print('bounds: {}'.format(','.join(vertices)))

detect_text('test.jpg')```

I get the following error:

Traceback (most recent call last):
File "main.py", line 38, in
detect_text('receipt1.jpg')
File "main.py", line 19, in detect_text
client = vision.ImageAnnotatorClient()
File "/home/XXXXXXXXXX/.local/lib/python3.7/site-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 165, in init
address=api_endpoint, channel=channel, credentials=credentials
File "/home/XXXXXXXXXX/.local/lib/python3.7/site-packages/google/cloud/vision_v1/gapic/transports/image_annotator_grpc_transport.py", lin
e 86, in init
channel
File "/home/XXXXXXXXXX/.local/lib/python3.7/site-packages/google/api_core/operations_v1/operations_client.py", line 59, in init
self.operations_stub = operations_pb2.OperationsStub(channel)
AttributeError: module 'google.longrunning.operations_pb2' has no attribute 'OperationsStub'


I installed the packages via `pip3 install google-cloud-storage google-cloud-vision` and have put the appropriate GOOGLE_APPLICATION_CREDENTIALS in my path so I'm pretty sure this is some kind of installation bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: visionIssues related to the Cloud Vision API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions