Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working #6

Closed
dangerrockstar opened this issue Jan 31, 2018 · 8 comments
Closed

not working #6

dangerrockstar opened this issue Jan 31, 2018 · 8 comments

Comments

@dangerrockstar
Copy link

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
Copy link
Owner

@dangerrockstar,

are you using pip for installing the package?

@dangerrockstar
Copy link
Author

yeah its add in my pip list but not working
untitled

@mattlisiv
Copy link
Owner

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
Copy link

heedro commented Feb 6, 2018

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
Copy link
Owner

@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
Copy link

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
Copy link
Owner

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants