2

我正在尝试导入Python Twitter库这可能是基本的事情。

首先我在第 52 行遇到错误,说他无法上传 json 库。那行代码是脚本的一部分,库根据 Python 的版本决定应该导入哪个 json 库。我评论了所有涉及其他版本的 Python 的行,而不是我正在使用的版本,并且它有效。

然后又弹出一个错误:

 Traceback (most recent call last):   
    File "<pyshell#0>", line 1, in <module>
 import twitter
    File "C:\Python32\lib\twitter.py", line 3448
 except urllib2.HTTPError, http_error:
                         ^ SyntaxError: invalid syntax

这个看不懂

我尝试在 2.6、2.7、3.1 和 3.2.2 版本中导入它,但没有任何效果。在一个中,我被要求提供 oauth 库,然后是 oauth2。第一个我做对了,第二个做错了。

我认为这应该适用于 3.2.2。谁能帮我?

提前致谢

4

1 回答 1

2

您提到的那个异常是尝试在 python 3 中运行的 Python 2 代码的语法错误。我可以说是因为 except 语法。

从项目页面:

Install the dependencies:

http://cheeseshop.python.org/pypi/simplejson
http://code.google.com/p/httplib2/
http://github.com/simplegeo/python-oauth2

来自http://pypi.python.org/pypi/python-twitter/

easy_install python-twitter或者pip install python-twitter应该工作。

于 2011-09-08T18:13:26.773 回答