簡體   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