python – ImportError: No module named twilio.rest

python – ImportError: No module named twilio.rest

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 youre using the version of Python you think youre 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

try this: sudo pip3 install twilio –upgrade

python – ImportError: No module named twilio.rest

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!

Leave a Reply

Your email address will not be published. Required fields are marked *