Forums

Twilio Libraries

I can't seem to import the twilio library. Both of these import calls fail:

  1. import twilio.twiml
  2. from twilio.rest import TwilioRestClient

This is particularly frustrating since the "batteries included" section indicates that Twilio is natively supported.

Which Python version are you using? We definitely have Twilio installed for Python 2.6 and Python 2.7, but not for 3.3 or 3.4. You can install them for your own account, though -- just run this from a bash console:

pip3.3 install --user twilio

(Or pip3.4 if you're using Python 3.4, of course.)

Alternatively, if you're using Python 2.6 or 2.7 and it's still not working, perhaps you're using a virtualenv and haven't installed Twilio into it?

Giles -

First off, thanks so much for taking the time to respond.

I am simply trying to run the generic "quick start" script found on the Twilio website. Trial and error shows me it's failing at the line "import twilio.twiml"

I have to run it through the web app on my account (because it must be publicly exposed to receive SMS.) I do not know how to tell which version of Twilio my pythonanywhere web app is running. However, I have now installed twilio, as you suggest, using pip3.3 and pip3.4.

I literally take a working app, add the line "import twilio.twiml", and it fails. Error message: Unhandled exception.

Any help would be greatly appreciated.

Hi there -- thanks for the extra details. The version of Python your web app uses is on the "Web" tab, in the "Code" section at the top. I've checked it out from our end, and it's using Python 3.3, which explains why you couldn't import twilio earlier.

If you check out your error log now (also in the "Web" tab, scroll to the bottom), you'll see that it's now complaining that it can't find the library socks. It's odd that the Twilio library didn't automatically install that when you installed it for Python 3.3, but you can install it for yourself with the following command:

pip3.3 install --user SocksiPy-branch

Hope that helps!

Wow - I was trying to find the content you refer to above, and in frustration I tried logging into pythonanywhere with Chrome rather than Safari. What a difference! Try it and see - in Safari, the Web tab shows virtually nothing.

Your fix worked! Socks is now installed.

Hey, how weird is it that no-one else has experienced this issue?

Interesting! I'm using Linux here, so I can't try Safari right now -- but I'll take a look when I get home this evening. Which version of Safari / OS X are you using, just in case I can't repro?

Anyway, thanks for confirming that it's fixed now :-) I reckon the reason no-one else has reported it is because most people are still using Python 2.7. 3.3 is better, and the community's definitely heading that way, but there are still a few roadblocks. I've made a note that we should install Twilio and SocksiPy-branch on our default system image, so at least we should be able to smooth this one out in a future update.

It's installed by default now for Python 3.3 and 3.4. We've also upgraded the version we already had for 2.7 (which means that it works properly from free accounts).