Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ImportError: No module named twilio.rest"

Tags:

python

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

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!

like image 209
Tomislav Avatar asked Feb 03 '16 14:02

Tomislav


3 Answers

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
like image 164
Marcos Placona Avatar answered Nov 01 '22 09:11

Marcos Placona


try this: sudo pip3 install twilio --upgrade

like image 20
hanumanDev Avatar answered Nov 01 '22 10:11

hanumanDev


I had this problem as well.

In my case, I had named my file twilio.py and that is what caused the error.

Renaming the file to send_sms.py ( or any other name of your choice) will resolve the issue!

like image 9
Nick Avatar answered Nov 01 '22 09:11

Nick