Forums

Tweepy Issues: AttributeError: module 'tweepy' has no attribute 'Client'

First time doing any kind of coding really, and I'm making a pretty simple Twitter bot using Tweepy. I've got it running pretty smoothly locally, but I'm having trouble getting it to do the same on here. When I run my script it only makes it to the second line before giving me that error - "AttributeError: module 'tweepy' has no attribute 'Client'". I tried using a virtualenv to use a newer release of Tweepy, but it still gives me the same thing. I really have no idea how to fix it, so any help would be greatly appreciated.

Which version of Tweepy do you have? According to the docs, tweepy.Client was introduced in version 4.0 -- I was able to install v. 4.5.0 on PythonAnyhwere on the latest system image in a virtual environment for Python 3.9 and import Client without any errors.

Also running v 4.5.0, to my knowledge. I didn't specify a version, I just did pip install tweepy which I believe should have given me the latest version, but I can try reinstalling it and specifying the version. I'll do that now. Update: Ok yeah, I tried reinstalling specifically 4.5.0 to the virtualenv, but I'm still having the same issue. This question is a bit silly but how do I make sure it is in fact using that virtual environment? I have it linked on my web app page, and reloaded, but is there anything I need to do when I'm actually running the script? Or will it just automatically use it?

If you want to install a package in a virtual env, you need to actiavate it, then run pip install <package-name> command. If you want to check which version of a package you're using run pip show <package-name>, while you're in the venv.

Yes I did do that, and it shows I am using v 4.5.0. I still get the same error though, regardless of what I try. If i try from tweepy import client (or Client), I get "ImportError: cannot import name 'client' from 'tweepy' (/usr/local/lib/python3.9/site-packages/tweepy/__init__.py)'". I'm specifically running the script in the virtualenv now, and I've made sure it's using the version of Tweepy I installed there in its directory search, but still no luck :-( I really cannot tell what the problem here is.

The error you see suggests that you're not running your code in the venv -- it tries to use preinstalled tweepy (from /usr/local/lib/python3.9/site-packages/tweepy/__init__.py). That preinstalled package is v. 3.10. Make sure you've activated the right venv.

Ah I figured it out now! I didn't realize I had to start Python from the bash console. Thank you for your patience and help lol ^^' Everything running nicely now

Oh, I see. Actually you can achieve that -- on the Consoles page you can set up a custom console. In order to do that, click on the "+" icon in the Custom row in "Start new console" section, give it a name and command, which in this case should be the path to python in your venv, e.g. /home/jackrabbit/.virtualenvs/foo/bin/python. Then you'll be able to start Python console in the venv directly from our UI.