Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'types' from 'google.cloud.vision' though I have google cloud vision installed

I have installed google-cloud-vision library following the documentation. It is for some reason unable to import types from google.cloud.vision. It worked fine on my pc, now when I shared with my client, he had a problem with imports though he has the library installed via pip. Here's the line that throws error:

from google.cloud import vision
from google.cloud.vision import types # this line throws error

Any idea how to resolve this issue?

like image 774
Hissaan Ali Avatar asked Nov 28 '22 05:11

Hissaan Ali


2 Answers

Use from google.cloud.vision_v1 import types instead of from google.cloud.vision import types.I have get this by exploring the init.py file and it works.

like image 189
Sumit Kumar Avatar answered Dec 05 '22 04:12

Sumit Kumar


Types module has been removed from google.cloud.vision from 2.0.0. You can access all the types from vision.

https://googleapis.dev/python/vision/latest/UPGRADING.html#enums-and-types

Before:

from google.cloud import vision_v1

likelihood = vision_v1.enums.Likelihood.UNKNOWN
request = vision_v1.types.GetProductSetRequest(name="name")

After:

from google.cloud import vision_v1

likelihood = vision_v1.Likelihood.UNKNOWN
request = vision_v1.GetProductSetRequest(name="name")
like image 25
Selva Prakash Avatar answered Dec 05 '22 03:12

Selva Prakash