“importorror:没有名为twilio.rest的模块”

2024-04-16 23:10:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了带有路径访问的Python2.7.10并正确安装了twilio。但是,当我尝试执行一个代码时,我会得到这个错误消息

Traceback (most recent call last):
  File "C:\Users\tmslvo\Google Drive\Desktop\send text.py", line 1, in <module>
    from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest

现在我看到一个原因可能是python找不到twilio包,所以我尝试了

which -a python
which -a twilio

命令(在我的Windows命令提示符中),在这种情况下

'which' is not recognized as an internal or external command,
operable program or batch file.

有人知道我做错了什么吗?

谢谢你!


Tags: or代码路径rest消息mostwhich错误
3条回答

我也遇到过同样的问题。我用easy_install代替pip来安装twilio,这就是问题所在。为了解决这个问题,我运行了pip uninstall twilio,并使用pip重新安装。

试试这个:sudo pip3 install twilio--upgrade

这里是Twilio开发者的福音传道者。

我想你的问题是,当你安装这个库时,它会以某种方式悄无声息地失败。有几件事要记住:

  1. 安装Python库时,请始终确保使用pip
  2. 另外,请检查项目中的任何文件实际上都不是名为twilio.py,因为这将与实际的库冲突。
  3. 通过运行python --version,检查您是否正在使用您认为正在使用的Python版本

所有这些都失败了,再次运行安装,并且一切正常(没有错误),您应该能够使用following code快速测试它。

import twilio
import twilio.rest

try:
    client = twilio.rest.TwilioRestClient(account_sid, auth_token)

    message = client.messages.create(
        body="Hello World",
        to="+14159352345",
        from_="+14158141829"
    )
except twilio.TwilioRestException as e:
    print e

相关问题 更多 >