'Python Ibm_watson: ImportError: cannot import name 'MyService'

I am trying to use IBM_Watson tone analyser in Python program. I was following this thread (IBM Cloud-Watson NLC - TypeError: __init__() got an unexpected keyword argument 'iam_apikey') to initiate the instance of IBM_Watson in the Python program. When I run the command from ibm_watson import MyService, it throws an error message of ImportError: cannot import name 'MyService'. Version 4.3.0 of Ibm_watson is installed on my machine. Has anyone came across the same issue?



Solution 1:[1]

This will be because you have the name of the service in the import wrong. Maybe a s for z typo, or a missing V3.

Based on the API Python SDK for the Tone Analysis - https://cloud.ibm.com/apidocs/tone-analyzer?code=python

from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
tone_analyzer = ToneAnalyzerV3(
    version='{version}',
    authenticator=authenticator
)

tone_analyzer.set_service_url('{url}')


Solution 2:[2]

I tried to import ToneAnalyzerV3 from ibm_watson using the code:

from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

But its showing:

"ImportError: cannot import name 'ToneAnalyzerV3' from 'ibm_watson' (/usr/local/lib/python3.7/dist-packages/ibm_watson/__init__.py)"

While I was installing ibm_watson library there was also another error

"ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
 google-colab 1.0.0 requires requests~=2.23.0, but you have requests 2.27.1 which is incompatible.
 datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible"

But when I rerun the cell containing the code

!pip install ibm_watson

it was gone. If anyone knows to solve this kindly reply soon.

Solution 3:[3]

Not completely sure but based on what you've said, it seems like you don't have an API key which is needed for Watson. An API key basically just shows you have the rights to the program. To get an API key, make an IBM Watson account and go to the part of Watson that you're using. Then you can generate an API key and put it into your program where you need to. Hope this helps!!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chughts
Solution 2 ramzeek
Solution 3 Blackshadow1Game