Pip + WSGI import errors
-
18-09-2019 - |
Question
when i deploy my apps that worked fine using the django test server I usually get errors for every package I installed using pip install -e ....#egg=foo. I usually do this using virtualenv, which placed the files into env/src/foo and places another file into python/site-packages (this is an example of django-css):
django-css.egg-link, which contains the following lines:
/home/pinax-0.7.1/src/django-css
.
how do i tell wsgi that it should follow those links, or am I doing something wrong altogether.
thanks, Philipp Wassibauer
Solution
This is what my WSGI script for Django in a virtualenv looks like:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import site
site.addsitedir('/path/to/virtualenv/lib/python2.6/site-packages')
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
The key bit is site.addsitedir(...)
, which adds the contents of any *.pth
files in the specified directory to sys.path
. In this case, it's the easy-install.pth
file that Python needs help finding.
OTHER TIPS
The modwsgi documentation has notes on how to use virtualenv. It is usually as simple as modifying your django.wsgi
(or whatever you call it) file so that it adds the virtualenv environment to modwsgi's path.
This link has some additional, distilled, notes on using pip/virtualenv/modwsgi.