4

I am having the same problem as this thread regarding twilio-python:

twilio.rest missing from twilio python module version 2.0.8?

However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.

Loading the library from stand alone python script works. So I know that pip installing the package worked.

from twilio.rest import TwilioRestClient


def main():
    account = "xxxxxxxxxxxxxxxx"
    token = "xxxxxxxxxxxxxxxx"
    client = TwilioRestClient(account, token)

    call = client.calls.create(to="+12223344", 
                               from_="+12223344", 
                               url="http://ironblanket.herokuapp.com/",
                               method="GET") 

if __name__ == "__main__":
    main()

but this does not work:

from twilio.rest import TwilioRestClient


def home(request):
    client = TwilioRestClient(account, token)

Do you have any idea what I can try next?

Community
  • 1
  • 1
David Dehghan
  • 22,159
  • 10
  • 107
  • 95
  • 4
    You're probably running the two scripts with different versions of python. Try running the second script with `/usr/bin/env python `. – Rob Wouters Jan 17 '12 at 00:02
  • I'm experiencing the same issue. When I navigate to `usr/bin/` I see that I have Python2.5, 2.6, and 2.7 installed. How do I update my default to be Python2.7? – Piper May 23 '13 at 16:51

4 Answers4

16

I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.

TLDR: just don't name your python file twilio.py

David Dehghan
  • 22,159
  • 10
  • 107
  • 95
  • 2
    Also important to remember to delete 'twilio.pyc' which may be less obvious ...or at least it was not so obvious to me in the couple of hours it took for me to realize the issue. – Joe Fusaro May 23 '15 at 13:34
1

Check which versions of pip and python you are running with this command:

which -a python
which -a pip

pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.

Check which version of the twilio module is installed by running this command:

$ pip freeze | grep twilio          # Or pip-2.7 freeze etc.

The output should be twilio==3.3.3.

I hope that helps - please leave a comment if you have more questions.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
  • I have tried with both python 2.7 and 2.6 . Here is the error from 2.6 http://pastebin.com/uRMeQhTH. my python and pip both point to the virtualenv that I have created. see http://pastebin.com/975Y5Xih – David Dehghan Jan 19 '12 at 22:54
0

This Worked For me : (Windows)

Python librarys are in G:\Python\Lib

(Python is installed at G:, it might be different for you)

Download Twilio from github at paste the library at >> G:\Python\Lib <<

import problem gone :)

Dipayan
  • 1
  • 2
0

I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:

AttributeError: module 'twilio' has no attribute 'version'

Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.

Installed to:

c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages

Moved it to: Traceback (most recent call last): File "", line 1, in import twilio File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in

Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.

Alien
  • 15,141
  • 6
  • 37
  • 57
rSeNaL
  • 1
  • 1