【问题标题】:Getting an error with Twitter Package in Python2.7Python2.7 中的 Twitter 包出错
【发布时间】:2013-07-23 08:52:59
【问题描述】:

我已经安装了 Python 2.7 并尝试使用 Twitter 包。我已经成功安装了 3 个必备软件包...但不知何故收到此错误:

>>> import twitter
>>> api = twitter.Api()
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    api = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'

我尝试了这个版本,但得到了同样的错误:

>>> api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',
                  access_token_key='access_token',
                  access_token_secret='access_token_secret')

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    api = twitter.Api(consumer_key='consumer_key',
AttributeError: 'module' object has no attribute 'Api'

我已经为 twitter 安装了 3 个软件包,即: python-twitter-0.8.5、python-twitter-1.0、twitter-1.10.0

命令的输出如下:

>>> twitter.__file__
'C:\\Python27\\lib\\site-packages\\twitter-1.10.0-py2.7.egg\\twitter\\__init__.pyc'

我应该卸载一些东西吗?我已在 python-twitter-0.8.5 和 python-twitter-1.0 中重命名了 twitter.py 文件,但仍然出现错误...

【问题讨论】:

  • twitter.__file__ 告诉您导入了什么?您当前的工作目录中可能还有另一个名为twitter.py 的文件。重命名它,它正在屏蔽模块。

标签: python python-2.7 twitter python-twitter


【解决方案1】:

您安装了一个不同的 Twitter API 模块;你安装了twitter 1.10.0,而不是python-twitter。两个项目之间的 API 差别很大:

import twitter

t = twitter.Twitter(
        auth=twitter.OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                   CONSUMER_KEY, CONSUMER_SECRET)
       )

您可能需要卸载 twitter 并安装 python-twitter

但是,如果您只需要一个好的 Python 推特 API 包,请查看list that Twitter maintainsTweepy 和一个不同的 python-twitter package 正在积极维护中。

【讨论】:

  • 谢谢,但是我看到的 Python-twitter 的问题是有 2 个这样的包... python-twitter-0.8.5 和 python-twitter-1.0 而且它们都支持 Python 2.4 而不是 Python 2.7。所以在我安装 twitter1.10 包之前,它一直在抱怨 Python 2.4 不存在......
  • @user2607677:更新了更好的选择。周围有一些冲突的包。
猜你喜欢
  • 1970-01-01
  • 2017-04-19
  • 2014-06-16
  • 2016-10-12
  • 2017-06-01
  • 1970-01-01
  • 2012-03-05
  • 1970-01-01
  • 2020-10-10
相关资源
最近更新 更多