【问题标题】:Python error syntax in the "tweepy" library [duplicate]“tweepy”库中的 Python 错误语法 [重复]
【发布时间】:2021-11-09 13:15:20
【问题描述】:

我遇到了 Python 中的 tweepy 库的问题。我在安装brew、piptweepy的过程中没有任何问题。

  • Python 版本是 Python 2.7.18
  • Pip 版本是 pip 21.3.1
  • Tweepy 版本是 4.3.0

我的代码如下:

import tweepy

consumer_key="XXX"
consumer_secret_key="XXX"
access_token="XXX-XXX"
access_token_secret="XXX"


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

print ("User Name:", api.me().name)
print ("Account (@):", api.me().screen_name)

我的问题是这段代码

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import tweepy
  File "/Library/Python/2.7/site-packages/tweepy-4.3.0-py2.7.egg/tweepy/__init__.py", line 12, in <module>
    from tweepy.api import API
  File "/Library/Python/2.7/site-packages/tweepy-4.3.0-py2.7.egg/tweepy/api.py", line 93
    self, auth=None, *, cache=None, host='api.twitter.com', parser=None,
                      ^
SyntaxError: invalid syntax

【问题讨论】:

  • 您不能在 Python 2.7 中使用该语法。无论如何,您现在应该使用 Python 3。
  • 有什么理由使用已经死了近 2 年的 Python 版本吗?

标签: python python-2.7 syntax tweepy


【解决方案1】:

这个问题是由于使用 Python 2.7 造成的。

如果您使用的是库,则需要使用它支持的 Python 版本。根据Tweepy's documentation,“支持Python 3.6 - 3.10。”

如果您坚持使用 Python 2.7,您也可能会遇到其他库的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-03
    • 2023-03-29
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2013-03-20
    • 2017-07-12
    • 2017-06-04
    相关资源
    最近更新 更多