Import error in twilio

I have the same issue as this topic regarding twilio-python :

is twilio.rest missing in twilio python module version 2.0.8?

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

Loading a library from a stand-alone python script works. Therefore, I know that the package installation 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?

+4
source share
3 answers

I named the python file in my twilio.py project. Since this file was downloaded first, subsequent calls to download twilio will refer to this file instead of the twilio library.

TL; DR: just don't name your python file twilio.py

+14
source

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

 which -a python which -a pip 

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

Verify which version of twilio is installed by running the following command:

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

The output should be twilio==3.3.3 .

I hope this helps - please leave a comment if you have further questions.

+1
source

This worked for me: (Windows)

Python libraries are located in the folder G: \ Python \ Lib

(Python is installed in G :, it may be different for you)

Download Twilio from github when pasting the library -> G: \ Python \ Lib <

import problem is gone :)

0
source

Source: https://habr.com/ru/post/1391346/


All Articles