【问题标题】:Pylint: Module/Instance of has no member for google.cloud.vision APIPylint:模块/实例没有 google.cloud.vision API 的成员
【发布时间】:2019-10-27 12:02:29
【问题描述】:

当我运行此代码(稍后将用于在 Python 中使用 Google Vision API 检测和提取文本)时,我收到以下错误:

模块 'google.cloud.vision_v1.types' 没有 'Image' 成员 pylint(no-member)

“ImageAnnotatorClient”实例没有“text_detection”成员 pylint(no-member)

from google.cloud import vision
from google.cloud.vision import types
import os, io

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'C:\Users\paul\VisionAPI\key.json'
client = vision.ImageAnnotatorClient()

FILE_NAME = 'im3.jpg'
FOLDER_PATH = r'C:\Users\paul\VisionAPI\images'


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

image = vision.types.Image(content=content)
response = client.text_detection(image=image)

“___ 的模块/实例没有成员”是什么意思?

【问题讨论】:

    标签: google-cloud-platform pylint google-cloud-vision


    【解决方案1】:

    我能够重现 pylint 错误,尽管脚本在运行时成功执行(对我的环境进行了微小的修改以更改正在处理的文件名)。

    因此,我假设“运行此代码”是指“通过 pylint 运行此代码”。如果没有,请更新问题,说明您是如何以产生 pylint 错误的方式执行代码的。

    This page 描述了您看到的具体错误,以及导致误报的情况。这很可能正是您遇到的误报。

    Google Cloud Vision 模块似乎是动态创建这些成员,而 pylint 无法检测它们在运行时是否实际存在,因此会引发错误。

    两种选择:

    • 按照上面链接页面中的建议,使用# pylint: disable=no-member 注释标记受影响的行。
    • 使用 --ignore-modules=google.cloud.vision_v1 标志运行 pylint(或将等效项放入 .pylintrc 中)。您会注意到,即使是实际的模块名称也与您导入的不同:)

    这是similar question,其中包含有关 E1101 错误解决方法的更多详细信息。

    【讨论】:

      猜你喜欢
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      相关资源
      最近更新 更多