简体   繁体   English

用于情感分析的 IBM 屈臣氏在导入时崩溃

[英]IBM watson for sentiment analysis crashing on import

I'm trying to use IBM watson for sentiment analysis.我正在尝试使用 IBM watson 进行情绪分析。 but it is crashing on the import: from ibm_watson import NaturalLanguageUnderstandingV1但它在导入时崩溃: from ibm_watson import NaturalLanguageUnderstandingV1

The whole code snippet is整个代码片段是

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

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

The error I'm seeing is我看到的错误是

/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

I'll appreciate any help.我将不胜感激任何帮助。 Thanks.谢谢。

The ibm-watson project description page mentions it's only tested on Python V3.x versions. ibm-watson 项目描述页面提到它仅在 Python V3.x 版本上进行了测试。

There is a lot of Python v3 syntax that is not compatible with Python v2.有很多 Python v3 语法与 Python v2 不兼容。

Since you mention you have Python v2, you should Python v3 instead if you want to using the ibm-watson library as is, you will have to use Python v3 .由于您提到您有 Python v2,如果您想按原样使用 ibm-watson 库,您应该使用 Python v3 ,您将不得不使用 Python v3

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

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