0

I have pip installed watson-developer-cloud, on python v3.5

I am simply trying to run one of the example codes: alchemy_data_news_v1.py Link:https://github.com/watson-developer-cloud/python-sdk/tree/master/examples

import json
from watson_developer_cloud import AlchemyLanguageV1

alchemy_data_news = AlchemyDataNewsV1(api_key='api-key')

results = alchemy_data_news.get_news_documents(start='now-7d', end='now',
                                               time_slice='12h')
print(json.dumps(results, indent=2))

results = alchemy_data_news.get_news_documents(
    start='1453334400',
    end='1454022000',
    return_fields=['enriched.url.title',
                   'enriched.url.url',
                   'enriched.url.author',
                   'enriched.url.publicationDate'],
    query_fields={
        'q.enriched.url.enrichedTitle.entities.entity':
            '|text=IBM,type=company|'})
print(json.dumps(results, indent=2))

I have also tried utilizing my own personal api-key and the result is the same:

File "c:\users\Joseph Sansevero\desktop\test.py", line 2, in watson_developer_cloud import AlchemyLanguageV1 ImportError: No module named watson_developer_cloud

Hristo Eftimov
  • 13,845
  • 13
  • 50
  • 77
  • First thing I notice, you're importing AlchemyLanguageV1 into your namespace, but referencing AlchemyDataNewsV1 which you haven't imported. But you're not actually getting to that. Have you pip installed anything else that works? Can you check for any errors in the pip install process? Have a look and see if the module is there? – Simon Hibbs Feb 11 '17 at 12:10
  • i have rerun the install multiple times and the same result is that it says a requirement is already satisfied, and then a long string of the file location. I double checked the file and it exists in the folder, with the alchemy file as well. – Joseph Sansevero Feb 11 '17 at 12:13
  • Maybe try just importing json and invoke one of it's methods to be sure that's imported ok? Maybe you're invoking a different Python install to the one you pip installed the library into? Check your PYTHONPATH? – Simon Hibbs Feb 11 '17 at 14:00
  • Json methods worked just fine. I am wondering if it is perhaps the syntax that i am using, or perhaps the import is importing the wrong thing? Sorry, I am rather new to python. – Joseph Sansevero Feb 11 '17 at 14:22

1 Answers1

0

Change your import statement to

from watson_developer_cloud import AlchemyLanguageV1

Alchemy language is a different api than AlchemyNews.

Head over to https://www.ibm.com/watson/developercloud/alchemydata-news/api/v1/?python#methods and you'll see the example has AlchemyNews imported.

Also make sure you install these packages using before running your code.

Gaurav Lath
  • 123
  • 1
  • 2
  • 8