mattlisiv / newsapi-python

A Python Client for News API
MIT License
404 stars 140 forks source link

not working #6

Closed dangerrockstar closed 6 years ago

dangerrockstar commented 6 years ago

from newsapi import NewsApiClient newsapi = NewsApiClient(api_key='e6702efb133e48418f78ea26f4620e20') top_headlines = newsapi.get_top_headlines(q='bitcoin', sources='bbc-news,the-verge', category='business', language='en', country='us') getting error in python3.x ImportError: cannot import name 'NewsApiClient'

mattlisiv commented 6 years ago

@dangerrockstar,

are you using pip for installing the package?

dangerrockstar commented 6 years ago

yeah its add in my pip list but not working untitled

mattlisiv commented 6 years ago

Could you replace your import with:

from newsapi.newsapi_client import NewsApiClient

It might be that the namespace is missing from the import statement.

heedro commented 6 years ago

I'm having the same issue after using pip to install.

When I use "from newsapi import NewsApiClient" I get: Traceback (most recent call last): File "newsapi.org\newsapi.py", line 7, in from newsapi import NewsApiClient File "newsapi.org\newsapi.py", line 7, in from newsapi import NewsApiClient ImportError: cannot import name 'NewsApiClient'

When I use "from newsapi.newsapi_client import NewsApiClient" i get: Traceback (most recent call last): File "newsapi.org\newsapi.py", line 7, in from newsapi.newsapi_client import NewsApiClient File "newsapi.org\newsapi.py", line 7, in from newsapi.newsapi_client import NewsApiClient ImportError: No module named 'newsapi.newsapi_client'; 'newsapi' is not a package

mattlisiv commented 6 years ago

@heedro,

It looks like you have named your script file "newsapi.py" . Is this correct?

If so, it can mix-up the namespace of the import statement. Try updating the filename and see if that resolves the issue.

reneewxy commented 6 years ago

Hi, I have the same problem. When I run the .py file, it always says "Import Error: cannot import name NewsApiClient." I want to add this api to google voice kit.

mattlisiv commented 6 years ago

I cannot seem to replicate this issue.

I have attempted a fresh install for both Windows and Mac. If someone would like to upload their project or define their setup (Python version, OS, etc.), I would be happy to assist.

For now, I have created a new example project that uses Docker to do a fresh install of Python, pip, and the NewsApi library to retrieve top headlines. I hope this helps.

https://github.com/mattlisiv/newsapi-docker

xidongsheng commented 5 years ago

my error is caused by my script file name newsapi.py, after i changed the filename, it works normally. @mattlisiv thanks your point