Pintint:的模块/实例没有google.cloud.vision API的成员

问题描述 投票:0回答:1

[当我运行此代码(以后将使用Python中的Google Vision API来检测和提取文本)时,出现以下错误:

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

'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个回答
0
投票

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

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

This page描述了您所看到的特定错误,以及导致其误报的情况。这很可能就是您所打的误报。

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

两个选项:

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

这是similar question,其中包含有关E1101错误的变通办法的更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.