- Implement virtualenv!
- Configure apache so that the python path is outside the virtual host
- Update wsgi.py to reference virtualenv path
/etc/apache2/sites-enabled/000-default
WSGIPythonPath /usr/local/django-user/app/:/usr/local/django-user/lib/python2.7/site-packages/
<VirtualHost *:8000>
ServerAdmin webmaster@localhost
ServerName localserver
WSGIScriptAlias / /usr/local/django-user/app/app/wsgi.py
AliasMatch ^/([^/]*\.css) /usr/local/django-user/app/static/styles/$1
Alias /static/ /usr/local/django-user/app/static/
<Directory /usr/local/django-user/app/app>
<Files wsgi.py>
Order deny,allow #Apache version dependent
allow from all #Apache version dependent
</Files>
</Directory>
...
wsgi.py
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/usr/local/django-user/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/app)
sys.path.append('/app/app)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
# Activate your virtual env
activate_env=os.path.expanduser("/usr/local/django-user/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()