“模块”对象没有属性“Twitter”;
我正在尝试遵循 O'Reilly 出版的《挖掘社交网络》一书第 5 页上的示例。我遇到以下错误:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'Twitter'
可能发生了什么?
I am trying to follow the example on page 5 of the book: Mining the Social Web, from O'Reilly. I am coming across the following error:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'Twitter'
What might be going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查 twitter.__file__ 的值(导入 twitter 后)。我的猜测是,要么您以某种方式获得了损坏的 twitter 版本,要么您在运行的同一目录中创建了一个名为 twitter.py 的文件,该文件阻止了已安装模块的加载。
如果
twitter.__file__
看起来不错(指向您安装的模块应该位于的位置,而不是本地目录),请尝试easy_install -U twitter
重新安装它。Check the value of
twitter.__file__
(after you've imported twitter). My guess is either you somehow got a broken version of twitter, or you've created a file called twitter.py in the same directory you're running from that's blocking the installed module from loading.If
twitter.__file__
looks good (points to where your installed modules should be instead of the local dir), tryeasy_install -U twitter
to reinstall it.对我有用。我通过
easy_install
安装了twitter
,它安装了最新版本(1.6.1)。dir(twitter)
还在此处列出了Twitter
。您可以从站点包中删除 twitter 包,然后尝试重新安装。
Works for me. I installed
twitter
througheasy_install
, which installed the latest version (1.6.1).dir(twitter)
also listsTwitter
here.You could remove the twitter package from site-packages and try reinstalling again.