0

I am getting an import error when trying to import twilio into a preexisting Django app. Here is what is happening/things I have tried:

The twilio package downloads to

(/home/ubuntu/.local/lib/python2.7/site-packages)

: This directory contains request package plus urllib3. Both of these seem to be dependencies for twilio. However, I have no idea if these were downloaded as dependencies or if they were already there from the original structure. If so, I don't know if other parts of the program require them.
The working location is

(/var/www/polar/venv/lib/python2.7/site-packages):

I moved twilio to this location and that is when the import twilio error went away, but this is when I got an import error for the request package. So I copied the request package and put it here, then I got import urllib3 error, did the same thing and got another import error from a file from the other directory. So it seems that the first location has a lot of the dependencies for twilio and the other location does not.

     My sys.path is:['',
                    '/usr/lib/python2.7',
                    '/usr/lib/python2.7/plat-x86_64-linux-gnu',
                     '/usr/lib/python2.7/lib-tk',
                     '/usr/lib/python2.7/lib-old',
                     '/usr/lib/python2.7/lib-dynload',
                     '/home/ubuntu/.local/lib/python2.7/site-packages',
                     '/usr/local/lib/python2.7/dist-packages',
                     '/usr/lib/python2.7/dist-packages']

ImportError at / No module named twilio.rest Request Method: GET Request URL: XXXXXXXXXX Django Version: 1.11.4 Exception Type: ImportError Exception Value: No module named twilio.rest Exception Location: /var/www/polar/frontend/views.py in , line 24 Python Executable: /var/www/polar/venv/bin/python Python Version: 2.7.12 Python Path: ['/var/www/polar', '/var/www/polar/venv/lib/python2.7', '/var/www/polar/venv/lib/python2.7/plat-x86_64-linux-gnu', '/var/www/polar/venv/lib/python2.7/lib-tk', '/var/www/polar/venv/lib/python2.7/lib-old', '/var/www/polar/venv/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/var/www/polar/venv/local/lib/python2.7/site-packages', '/var/www/polar/venv/lib/python2.7/site-packages']

This is the original error message. Anyone have any ideas or suggestions this has been driving me crazy for a bit now?

3
  • did you activate your virtual environment? Commented Jun 4, 2018 at 14:00
  • I believe it is activated. This is an application that someone else made and i am just trying to expand it. I also am not very experienced in this realm, so I could be wrong. Would this venv be different than one currently on the working app? Commented Jun 4, 2018 at 14:03
  • Worth mentioning, if I run the test code in my putty terminal, it works. Just not when I run the application via the browser. Commented Jun 4, 2018 at 14:41

1 Answer 1

0

I finally got this fixed. @Abihijith Asokan was right. For anyone else who runs into this issue with Django. Basically, there are two environments inside my Django App, one outside environment, one working environment. It was originally installing to this outside environment, so the app could not find it. All I had to do was activate my virtual environment.

  • Locate your activate file, mine was(/var/www/project_name/venv/bin/activate)
  • in the terminal run source /path/to/project/activate
  • then install twilio with pip

Now it installed to a different directory and works with out problems.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.