Python “导入错误:没有名为 twilio.rest 的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35180322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"ImportError: No module named twilio.rest"
提问by Tomislav
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
我已经安装了具有 PATH 访问权限的 python 2.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
Now I read that a reason might be that python can't find the twilio package so I tried the
现在我读到一个原因可能是 python 找不到 twilio 包所以我尝试了
which -a python
which -a twilio
commands (in my Windows command prompt) in which case I get
命令(在我的 Windows 命令提示符中)在这种情况下我得到
'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?
有人知道我做错了什么吗?
Thank you!
谢谢!
回答by Marcos Placona
Twilio developer evangelist here.
Twilio 开发人员布道者在这里。
I think your problem will be that somehow when you installed the library, it failed silently(?). A few things to keep in mind:
我认为你的问题是当你安装库时,它以某种方式失败了(?)。需要牢记以下几点:
- When installing Python libraries, always make sure you use pip.
- Also, check that none of your files within the project are actually called
twilio.py
as this will conflict with the actual library. - Check that you're using the version of Python you think you're using by running
python --version
- 安装 Python 库时,请始终确保使用pip。
- 此外,请检查项目中的所有文件是否实际被调用,
twilio.py
因为这会与实际库冲突。 - 通过运行来检查您使用的是您认为正在使用的 Python 版本
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
回答by Vizz85
Close and then relunch all IDLE instances.
关闭并重新启动所有 IDLE 实例。
This sounds obvious but it worked for me, since the installations of components were successful
这听起来很明显,但它对我有用,因为组件安装成功
回答by Dave Justen
I ran into this same issue. I had used easy_install instead of pip to install twilio which was the problem. To fix this I ran pip uninstall twilio
and reinstalled using pip.
我遇到了同样的问题。我使用 easy_install 而不是 pip 来安装 twilio,这是问题所在。为了解决这个问题,我运行pip uninstall twilio
并使用 pip 重新安装。
回答by José Manuel Carranza
Pycharm user:
pycharm 用户:
Macs (mid 2017) come with python 2.6
and 2.7
installed. PyCharm
uses by default 2.6
. When you install twilio
(Pip install) the module is installed in python version 2.7
. So, when you try to run twilio
from PyCharm
you get
Mac(2017 年中)随附python 2.6
并2.7
安装。PyCharm
默认使用2.6
. 当您安装twilio
(Pip install) 时,模块安装在 python 版本中2.7
。所以,当你试图逃跑时twilio
,PyCharm
你会得到
ImportError: No module named twilio.rest
ImportError: No module named twilio.rest
Solution: change the python interpreter in PyCharm
. Go to preferences > project interpreter
and from the drop menu Project Interpreter
choose python 2.7
解决方案:在PyCharm
. 转到preferences > project interpreter
并从下拉菜单中Project Interpreter
选择python 2.7
回答by Vinay Kumar
rename file name other than twilio.py EX:send_sms.py
重命名 twilio.py 以外的文件名 EX:send_sms.py
回答by Arun
I think your pip is not configured properly . You may be getting succefuuly installed message but it is not install where it should be. try pip install --user i am sure it will work for you. pip install may work fine only in virtualenvironment without any config.Try pip install --user package name
我认为您的 pip 配置不正确。您可能会收到成功安装的消息,但它没有安装在它应该安装的位置。尝试 pip install --user 我相信它对你有用。pip install 只能在没有任何配置的虚拟环境中正常工作。尝试 pip install --user 包名
@iosCurator
@iosCurator
回答by hanumanDev
try this: sudo pip3 install twilio --upgrade
试试这个: sudo pip3 install twilio --upgrade
回答by user3118443
I had first installed twilio with the easy_intall
tool
我首先使用该easy_intall
工具安装了 twilio
I followed the steps below:
我按照以下步骤操作:
- Uninstall twilio with the command
pip uninstall twillo
- Install twilio with the command
pip install twilio
- Close the python IDLE and relaunch it.
- 使用命令卸载 twilio
pip uninstall twillo
- 使用命令安装 twilio
pip install twilio
- 关闭 python IDLE 并重新启动它。
回答by Nick
I had this problem as well.
我也有这个问题。
In my case, I had named my file twilio.py
and that is what caused the error.
就我而言,我已经命名了我的文件twilio.py
,这就是导致错误的原因。
Renaming the file to send_sms.py
( or any other name of your choice) will resolve the issue!
将文件重命名为send_sms.py
(或您选择的任何其他名称)将解决问题!