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

ImportError: cannot import name 'API' from 'tweepy' (unknown location) #30

Open
tarensss opened this issue Jun 23, 2022 · 1 comment
Open

Comments

@tarensss
Copy link

Hi I am using a 2020 mac book air

I am getting this error the same issue was closed but it worked on Windows.
I am using the recent Twitter API.

/Users/apple/project/Mining-twitter-data-with-pyth
on/Tweet/my_env/bin/python /Users/apple/project/Mining-twitter-data-with-python/Tweet/tw
itter_get_home_timeline.py
Traceback (most recent call last):
File "/Users/apple/project/Mining-twitter-data-with-python/Tweet/twitter_get_home_timeline.py", line 14, in
from twitter_client import get_twitter_client
File "/Users/apple/project/Mining-twitter-data-with-python/Tweet/twitter_client.py", line 11, in
from tweepy import API
ImportError: cannot import name 'API' from 'tweepy' (unknown location)

@bonzanini
Copy link
Owner

Hi @Tarandeepsingh436 you might be experiencing different issues.

Firstly, please be aware that the code here supports the old Twitter API v1, so if you're using the latest v2 things simply won't work out of the box, loads of things have changed since this book came out in 2016. You may want to explore how tweepy supports the new API version and customise your code accordingly (https://docs.tweepy.org/en/stable/install.html) but I can't offer much advice there.

If you're working with the Twitter API v1 instead, you can use the code here but there are a couple more things to check:

  • Please make sure you don't have a file called tweepy.py in that same folder, that might cause import issues.

  • Also make sure to activate the Python virtual environment correctly, and run it from the source code folder, e.g. simply:

    python twitter_get_home_timeline.py

On Mac you can check which Python interpreter you're running with:

which python

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

2 participants