Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tweepy won't install on python 3.7; shows "syntax error"

Before I begin, I'd like to preface that I'm relatively new to python, and haven't had to use it much before this little project of mine. I'm trying to make a twitter bot as part of an art project, and I can't seem to get tweepy to import. I'm using macOS High Sierra and Python 3.7. I first installed tweepy by using

pip3 install tweepy

and this appeared to work, as I'm able to find the tweepy files in finder. However, when I simply input

import tweepy

into the IDLE, I get this error:

Traceback (most recent call last):
File "/Users/jacobhill/Documents/CicadaCacophony.py", line 1, in <module>
  import tweepy
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tweepy/__init__.py", line 17, in <module>
  from tweepy.streaming import Stream, StreamListener
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tweepy/streaming.py", line 358
  def _start(self, async):
                         ^
SyntaxError: invalid syntax

Any idea on how to remedy this? I've looked at other posts on here and the other errors seem to be along the lines of "tweepy module not found", so I don't know what to do with my error. Thanks!

like image 410
Jacob Hill Avatar asked Dec 23 '22 05:12

Jacob Hill


2 Answers

Using async as an identifier has been deprecated since Python 3.5, and became an error in Python 3.7, because it's a keyword.

This Tweepy bug was reported on 16 Mar, and fixed on 12 May, but there hasn't been a new release yet. Which is why, as the repo's main page says:

Python 2.7, 3.4, 3.5 & 3.6 are supported.


For the time being, you can install the development version:

pip3 install git+https://github.com/tweepy/tweepy.git

Or, since you've already installed an earlier version:

pip3 install --upgrade git+https://github.com/tweepy/tweepy.git

You could also follow the instructions from the repo:

git clone https://github.com/tweepy/tweepy.git
cd tweepy
python3 setup.py install

However, this will mean pip may not fully understand what you've installed.

like image 84
abarnert Avatar answered Dec 25 '22 20:12

abarnert


In Python3.7, async became a reserved word (as can be seen in whats new section here) and therefore cannot be used as argument. This is why this Syntax Error is raised.

That said, and following tweetpys official GitHub (here), only

Python 2.7, 3.4, 3.5 & 3.6 are supported.


However, if you really must use Python3.7, there is a workaround. Following this suggestion, you can

open streaming.py and replace async with async_

and it should work

like image 29
rafaelc Avatar answered Dec 25 '22 20:12

rafaelc