简体   繁体   English

导入错误:虽然我安装了谷歌云视觉,但无法从“google.cloud.vision”导入名称“types”

[英]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.我已经按照文档安装了 google-cloud-vision 库。 It is for some reason unable to import types from google.cloud.vision .由于某种原因无法从google.cloud.vision导入types 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.它在我的电脑上运行良好,现在当我与我的客户共享时,尽管他通过 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?知道如何解决这个问题吗?

Use from google.cloud.vision_v1 import types instead of from google.cloud.vision import types .使用from google.cloud.vision_v1 import types而不是from google.cloud.vision import types I have get this by exploring the init.py file and it works.我通过探索 init.py 文件得到了这个,它可以工作。

Types module has been removed from google.cloud.vision from 2.0.0.类型模块已从 google.cloud.vision 从 2.0.0 中删除。 You can access all the types from vision.您可以从视觉访问所有类型。

https://googleapis.dev/python/vision/latest/UPGRADING.html#enums-and-types 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")

It's probably because there's some version mismatch (or less likely there's other library(s) with the same name).这可能是因为版本不匹配(或者不太可能有其他同名的库)。 Have your client use a virtual environment.让您的客户使用虚拟环境。 This should resolve the issue.这应该可以解决问题。

PS You'll have to provide him with a requirements.txt file (obtained from pip3 freeze ) so that he can do a pip3 install -r requirements.txt on his virtual environment to have the exact same packages as yours. PS 您必须向他提供一个requirements.txt文件(从pip3 freeze获得),以便他可以在他的虚拟环境中执行pip3 install -r requirements.txt以获得与您的完全相同的包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM