首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法进口Tweepy

无法进口Tweepy
EN

Stack Overflow用户
提问于 2015-08-22 05:06:59
回答 2查看 8.3K关注 0票数 0

我在跟踪本教程,我被困在Tweepy安装上了。我按照来自sudo pip install tweepy的说明运行了Tweepy的github页面,安装成功了:

成功安装

代码语言:javascript
复制
User-MBP:Mercuria user$ sudo pip install tweepy
Downloading/unpacking tweepy
  Downloading tweepy-3.4.0-py2.py3-none-any.whl
Downloading/unpacking requests>=2.4.3 (from tweepy)
  Downloading requests-2.7.0-py2.py3-none-any.whl (470kB): 470kB downloaded
Downloading/unpacking six>=1.7.3 (from tweepy)
  Downloading six-1.9.0-py2.py3-none-any.whl
Downloading/unpacking requests-oauthlib>=0.4.1 (from tweepy)
  Downloading requests_oauthlib-0.5.0-py2.py3-none-any.whl
Downloading/unpacking oauthlib>=0.6.2 (from requests-oauthlib>=0.4.1->tweepy)
  Downloading oauthlib-1.0.3.tar.gz (109kB): 109kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/oauthlib/setup.py) egg_info for package oauthlib

Installing collected packages: tweepy, requests, six, requests-oauthlib, oauthlib
  Found existing installation: requests 2.1.0
    Uninstalling requests:
      Successfully uninstalled requests
  Found existing installation: requests-oauthlib 0.4.0
    Uninstalling requests-oauthlib:
      Successfully uninstalled requests-oauthlib
  Found existing installation: oauthlib 0.6.1
    Uninstalling oauthlib:
      Successfully uninstalled oauthlib
  Running setup.py install for oauthlib

Successfully installed tweepy requests six requests-oauthlib oauthlib
Cleaning up...

异常

代码语言:javascript
复制
User-MBP:Mercuria user$ python feed.py 
Traceback (most recent call last):
  File "feed.py", line 2, in <module>
    from tweepy.streaming import StreamListener
ImportError: No module named tweepy.streaming

我正在运行的代码可以在教程页面中找到,并在下面粘贴:

代码语言:javascript
复制
#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#Variables that contains the user credentials to access Twitter API 
access_token = "ENTER YOUR ACCESS TOKEN"
access_token_secret = "ENTER YOUR ACCESS TOKEN SECRET"
consumer_key = "ENTER YOUR API KEY"
consumer_secret = "ENTER YOUR API SECRET"


#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):

    def on_data(self, data):
        print data
        return True

    def on_error(self, status):
        print status


if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    stream.filter(track=['python', 'javascript', 'ruby'])
EN

回答 2

Stack Overflow用户

发布于 2016-04-10 13:17:23

也有同样的问题。对我来说,这是由于在我的系统上安装了多个版本的python。为了解决这个问题,我不得不做以下工作: v2.7

代码语言:javascript
复制
pip install tweepy

3.0版

代码语言:javascript
复制
pip3 install tweepy

第3.5节:

代码语言:javascript
复制
pip3.5 install tweepy
票数 2
EN

Stack Overflow用户

发布于 2015-08-22 05:44:22

我想您想尝试使用python版本的pip版本。如果您有python2.7.7,只需运行:Sudopip2.7安装tweepy,它在python 2.7.6中对我有效。

代码语言:javascript
复制
>>> from tweepy.streaming import StreamListener
>>> dir(StreamListener)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'keep_alive', 'on_connect', 'on_data', 'on_delete', 'on_direct_message', 'on_disconnect', 'on_error', 'on_event', 'on_exception', 'on_friends', 'on_limit', 'on_status', 'on_timeout', 'on_warning']

你为什么要尝试从tweepy.streaming,而不是仅仅是推特?

代码语言:javascript
复制
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
>>> import tweepy
>>> from tweepy import StreamListener
>>> dir(StreamListener)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'keep_alive', 'on_connect', 'on_data', 'on_delete', 'on_direct_message', 'on_disconnect', 'on_error', 'on_event', 'on_exception', 'on_friends', 'on_limit', 'on_status', 'on_timeout', 'on_warning']
>>> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32152539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档