簡體   English   中英

用於情感分析的 IBM 屈臣氏在導入時崩潰

[英]IBM watson for sentiment analysis crashing on import

我正在嘗試使用 IBM watson 進行情緒分析。 但它在導入時崩潰: from ibm_watson import NaturalLanguageUnderstandingV1

整個代碼片段是

import json 
import constants from ibm_watson import NaturalLanguageUnderstandingV1 from ibm_cloud_sdk_core.authenticators
import IAMAuthenticator from ibm_watson.natural_language_understanding_v1 import Features, SentimentOptions

class SentimentAnalysis:

    def __init__(self):
        authenticator = IAMAuthenticator(constants.IBM_WATSON_KEY)
        this.natural_language_understanding = NaturalLanguageUnderstandingV1(
            version='2020-08-01',
            authenticator=authenticator
        )
        this.natural_language_understanding.set_service_url(constants.IBM_WATSON_URL)

    def analyse_sentiments(self, data):
        response = this.natural_language_understanding.analyze(
            text=data,
            features=Features(sentiment=SentimentOptions())).get_result()
        assert isinstance(response, object)
        return response

我的 python 版本是 Python 2.7.16 Installed IBM watson using pip install --upgrade "ibm-watson>=4.6.0"

我看到的錯誤是

/usr/bin/python /Users/rabbal1892/Desktop/DeepInsight/nextcontent-etl/scrapers/sentiment_analysis.py Traceback (most recent call last):   File "/Users/rabbal1892/Desktop/DeepInsight/nextcontent-etl/scrapers/sentiment_analysis.py", line 3, in <module>
    from ibm_watson import NaturalLanguageUnderstandingV1   File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_watson/__init__.py", line 16, in <module>
    from ibm_cloud_sdk_core import IAMTokenManager, DetailedResponse, BaseService, ApiException   File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_cloud_sdk_core/__init__.py", line 34, in <module>
    from .base_service import BaseService   File "/Users/rabbal1892/Library/Python/2.7/lib/python/site-packages/ibm_cloud_sdk_core/base_service.py", line 68
    service_url: str = None,
               ^ SyntaxError: invalid syntax

我將不勝感激任何幫助。 謝謝。

ibm-watson 項目描述頁面提到它僅在 Python V3.x 版本上進行了測試。

有很多 Python v3 語法與 Python v2 不兼容。

由於您提到您有 Python v2,如果您想按原樣使用 ibm-watson 庫,您應該使用 Python v3 ,您將不得不使用 Python v3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM