小编cur*_*4cs的帖子

导入错误:无法在 Google Cloud Language API 中导入名称语言

我正在尝试使用 Google Natural Language API 中的此示例代码来获取情绪分数。但是,每次运行代码时,都会收到“ImportError:无法导入名称语言”。第一行出错。

我已经 pip 安装了该库,尝试卸载并重新安装,在控制台上创建凭据(显示 API 已启用)并查看本教程并完成了答案中的这些步骤:Google 情绪分析 - 导入错误:无法导入名称语言。它没有帮助。还有什么我可以尝试的吗?

from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

client = language.LanguageServiceClient()

text = u'Hello, world!'
document = types.Document(
    content=text,
    type=enums.Document.Type.PLAIN_TEXT)

sentiment = client.analyze_sentiment(document=document).document_sentiment

print('Text: {}'.format(text))
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))
Run Code Online (Sandbox Code Playgroud)

我还使用正确的路径将其粘贴到我的终端中。

export GOOGLE_APPLICATION_CREDENTIALS="/....(my path)/service_key.json"
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

Traceback (most recent call last):
  File "lang.py", line 3, in <module>
    from google.cloud import language
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/cloud/language.py", line 17, in <module>
    from google.cloud.language_v1 import LanguageServiceClient
  File …
Run Code Online (Sandbox Code Playgroud)

python google-api google-cloud-platform google-cloud-functions google-natural-language

4
推荐指数
2
解决办法
9401
查看次数

给定数百万个数字流,如何近似计算第 90 个百分位数

我需要计算每秒获得的数字流的第 90 个百分位数。它可能高达每秒数百万个数字,但第 90 个百分位数只需要近似,不一定准确。优先队列/最大堆是执行此操作的最佳方法还是其他方法?如果是这样,我最终将如何估算该值?

java heap statistics priority-queue percentile

2
推荐指数
1
解决办法
2487
查看次数