“ImportError: No module named twilio.rest”

微笑、不失礼 提交于 2019-12-12 10:36:57

问题


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

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

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?

Thank you!


回答1:


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. 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



回答2:


try this: sudo pip3 install twilio --upgrade




回答3:


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.




回答4:


Close and then relunch all IDLE instances.

This sounds obvious but it worked for me, since the installations of components were successful




回答5:


Pycharm user:

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

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




回答6:


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

@iosCurator




回答7:


I had first installed twilio with the easy_intall tool

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.



回答8:


rename file name other than twilio.py EX:send_sms.py



来源:https://stackoverflow.com/questions/35180322/importerror-no-module-named-twilio-rest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!