繁体   English   中英

来自google.cloud导入语言ImportError:没有名为cloud的模块

[英]from google.cloud import language ImportError: No module named cloud

尝试使用Google情感分析。 这是我从Google教程中获得的代码。

msgstr“”“演示如何对Natural Language API进行简单调用。”“

import argparse

from google.cloud import language


def print_result(annotations):
    score = annotations.sentiment.score
    magnitude = annotations.sentiment.magnitude

    for index, sentence in enumerate(annotations.sentences):
        sentence_sentiment = sentence.sentiment.score
        print('Sentence {} has a sentiment score of {}'.format(
            index, sentence_sentiment))

    print('Overall Sentiment: score of {} with magnitude of {}'.format(
        score, magnitude))
    return 0

    print('Sentiment: score of {} with magnitude of {}'.format(
        score, magnitude))
    return 0


def analyze(movie_review_filename):
    """Run a sentiment analysis request on text within a passed filename."""
    language_client = language.Client()

    with open(movie_review_filename, 'r') as review_file:
        # Instantiates a plain text document.
        document = language_client.document_from_html(review_file.read())

        # Detects sentiment in the document.
        annotations = document.annotate_text(include_sentiment=True,
                                             include_syntax=False,
                                             include_entities=False)

        # Print the results
        print_result(annotations)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        'movie_review_filename',
        help='The filename of the movie review you\'d like to analyze.')
    args = parser.parse_args()

    analyze(args.movie_review_filename)

运行代码我收到以下错误:

来自google.cloud导入语言ImportError:没有名为cloud的模块

您需要安装实际的Google SDK Python模块。 google-cloud库是pip install-able:

pip install --upgrade google-cloud

在这里查看更多。

我使用python -m pip install google-cloud而且它有效! 我有同样的问题。我的问题是由pip.Pip引起的,是在错误的目录中安装google-cloud。

暂无
暂无

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

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