本文介绍了“导入错误:没有名为 twilio.rest 的模块";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了具有 PATH 访问权限的 python 2.7.10 并正确安装了 twilio.但是,当我尝试执行代码时,我收到此错误消息

I have installed python 2.7.10 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message

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包所以我尝试了

Now I read that a reason might be that python can't find the twilio package so I tried the

which -a python
which -a twilio

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

commands (in my Windows command prompt) in which case I get

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

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

Does anybody have an idea of what I'm doing wrong?

谢谢!

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

我认为您的问题是,当您安装库时,不知何故,它无声无息地失败了(?).需要记住的一些事项:

I think your problem will be that somehow when you installed the library, it failed silently(?). A few things to keep in mind:

  1. 安装 Python 库时,请务必使用 pip.
  2. 此外,请检查项目中的所有文件是否实际上都称为 twilio.py,因为这会与实际库冲突.
  3. 通过运行 python --version
  4. 检查您使用的 Python 版本是否是您认为正在使用的 Python 版本
  1. When installing Python libraries, always make sure you use pip.
  2. Also, check that none of your files within the project are actually called twilio.py as this will conflict with the actual library.
  3. Check that you're using the version of Python you think you're using by running python --version

所有这些都失败了,再次运行安装,一切顺利(没有错误),您应该能够使用 以下代码.

All that failing, run the installation again, and all going well (without errors), you should be able to test it quickly with the 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

这篇关于“导入错误:没有名为 twilio.rest 的模块";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:42