I am getting trouble getting Apache/WSGI to make use of my VirtualEnv. I've added the next two lines (path on server is pointing towards the actual location of site-packages within the target virtualenv) to my WSGI file:

import site

(from http://www.foxhop.net/django-virtualenv-apache-mod_wsgi). However, after i attempt to load the url within the browser I recieve a 500. Checking the apache logs:

 [Sun Jul 17 11:07:11 2011] [error] [client]     app =   import_module(appname)
[Sun Jul 17 11:07:11 2011] [error] [client]   File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
[Sun Jul 17 11:07:11 2011] [error] [client]     __import__(name)
[Sun Jul 17 11:07:11 2011] [error] [client] TemplateSyntaxError: Caught ImportError while rendering: No module named tagging
[Sun Jul 17 11:07:11 2011] [debug] mod_deflate.c(615): [client] Zlib: Compressed 629 to 387 : URL /

And So I reckon that the VirtualEnv is not being loaded. Anybody understand how to tell Apache / WSGI the right virtualenv to make use of?


I've up-to-date django.wsgi following Ken's advice, but now i'm obtaining the following error within the apache log

[Sun Jul 17 16:46:36 2011] [info] [client] mod_wsgi (pid=11260, process='', application='igniteflow-django.com:8090|'): Loading WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client] mod_wsgi (pid=11260): Target WSGI script '/sites/igniteflow/apache/django.wsgi' cannot be loaded as Python module.
[Sun Jul 17 16:46:36 2011] [error] [client] mod_wsgi (pid=11260): Exception occurred processing WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client] Traceback (most recent call last):
[Sun Jul 17 16:46:36 2011] [error] [client]   File "/sites/igniteflow/apache/django.wsgi", line 5, in <module>
[Sun Jul 17 16:46:36 2011] [error] [client]     execfile(activate_this, dict(__file__=activate_this))
[Sun Jul 17 16:46:36 2011] [error] [client] IOError: [Errno 13] Permission denied: '/root/.virtualenvs/igniteflow/bin/activate_this.py'

I suppose the reason being the virtualenv is within root and apache does not have permissions? I chowned the folder to root:www-data however it has not fixed the issue. Any suggestions?

During my application.wsgi file I've something similar to this. You will have to change it out to offer where your virtual env is situated, mine is under /opt/ve/ve_title/ within this example.

import os
# activate virtualenv
activate_this = os.path.expanduser("/opt/ve/ve_name/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))