2017-06-15 33 views
-3

我跑這個簡單的.py:Eror導入tweepy?

from tweepy import Stream 
from tweepy import OAuthHandler 
from tweepy.streaming import StreamListener 
ckey = '' 
csecret = '' 
atoken = '' 
asecret = '' 

class Listener(StreanListener): 
    def on_data(self, data): 
     print data 
     return True 

    def on_error(self, status): 
     print status 

OAuthHandler(ckey, csecret) 
auth.set_access_token(atoken, asecret) 
twitterStream = Strean(auth, Listener()) 
twitterStream.filter(track=["tour de france"]) 

和我得到這個錯誤:

File "twe.py", line 1, in <module> 
    from tweepy import Stream 
    File "/Users/Raz-mac/Documents/tweepy.py", line 1 
    git clone https://github.com/tweepy/tweepy.git 

我猜測它涉及到進口tweepy? 我該如何解決這個問題?

+0

你安裝了嗎? ** git clone https://github.com/tweepy/tweepy.git, cd tweepy, python setup.py install ** – Stack

+0

謝謝你們。我使用的是mac osx,即使安裝了tweepy,我仍然收到錯誤信息(我檢查過了,我有庫和tweepy文檔) – rm21

回答

0

可以執行下面的一組動作:

1)安裝虛擬環境(Linux上): $ virtualenv env

2)運行新的虛擬環境 $ source env/bin/activate

3)安裝tweepy庫: (env)$ pip install tweepy

and 一切都會好的:

(env)$ python 
>>> from tweepy import Stream 
>>> 
+0

嗨,我安裝了virtualenv並創建了一個新環境,激活了環境並運行了相同的代碼。我仍然遇到同樣的錯誤。任何想法爲什麼? – rm21