2016-06-07 50 views
0

似乎我已安裝twilio。從我的終端:終端說Twilio安裝; IDLE不會運行它

sudo easy_install twilio 

Password: Searching for twilio Best match: twilio 6.3.dev0 Processing twilio-6.3.dev0-py2.7.egg twilio 6.3.dev0 is already the active version in easy-install.pth

Using /Library/Python/2.7/site-packages/twilio-6.3.dev0-py2.7.egg Processing dependencies for twilio Finished processing dependencies for twilio"

然而,當我嘗試安裝測試:

from twilio.rest import TwilioRestClient 

account_sid = "{{SK5f7498ffc677d5071f1e8505f622e04d}}" # Your Account SID from www.twilio.com/console 
auth_token = "{{4xhl9pCzyd1oO5VRiMvWq9lIaiVgkvKd}}" # Your Auth Token from www.twilio.com/console 

client = TwilioRestClient(account_sid, auth_token) 

message = client.messages.create(body="My name is Ron Burgandry?", 
    to="+16509954344", # Replace with your phone number 
    from_="+16504828319") # Replace with your Twilio number 

print(message.sid) 

我收到以下錯誤:

traceback (most recent call last): File "/Users/jonathangheller/Documents/send_text.py", line 1, in from twilio.rest import TwilioRestClient ImportError: No module named 'twilio'"

+0

你沒有使用pip安裝的任何特定原因? https://www.twilio.com/docs/libraries/python –

+0

我得到一個命令未找到錯誤,文檔建議在這種情況下使用easy_install – user449914

回答

1

所有你需要做的終端是

pip3 install twilio --upgrade 

如果已安裝pip,請添加「升級」。如果未安裝,先安裝pip,然後運行上述命令。這解決了我的問題。

我得到這個錯誤的原因是我的空閒時運行python 3.5.2,而終端運行python 2.7.1。如果我使用python3將終端上的python版本更改爲版本3.5.1,則導入twilio命令會出現上述錯誤。這個問題已被上述命令修復。

+0

感謝它也爲我工作! – SurjanSRawat