Apache not getting access to virtual environment set up for Django project
Question: I created a virtualenv named '`pyapps`' and installed pinax and django in
it.I've installed apache 2 and mod_wsgi.I created a directory named '`apache`'
inside my django project(`testproject`) and put '`django.wsgi`' file inside
that directory.Here is the content of my wsgi file:

    
    
    import os
    import sys
    
    # put the Django project on sys.path
    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'textpisodes.settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

Then I created a directory '`/check/www`' and put my project folder and
`pyapps` folder inside '`/check/www`'.I chmoded 777 on `/check/www`.

Finally I created a virtual host,it's content is as follows:

    
    
    <VirtualHost *:80>
        ServerAdmin myemail
        ServerName djangoserver
    
        WSGIDaemonProcess textpisodes user=rajat threads=10 python-path=/check/www
        WSGIProcessGroup textpisodes
    
        WSGIScriptAlias / /check/www/textpisodes/apache/django.wsgi
        <Directory /check/www/textpisodes/apache>
            Order deny,allow
            Allow from all
        </Directory>
    
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
    
        CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
    

Now when I try to access 'http://djangoserver',all I'm getting is `Internal
Server Error`.Here are the contents of my apache log file.

    
    
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] mod_wsgi (pid=4890): Target WSGI script '/check/www/textpisodes/apache/django.wsgi' cannot be loaded as Python module.
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] mod_wsgi (pid=4890): Exception occurred processing WSGI script '/check/www/textpisodes/apache/django.wsgi'.
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1]   File "/check/www/textpisodes/apache/django.wsgi", line 9, in <module>
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1]     import django.core.handlers.wsgi
    [Thu Sep 13 18:39:51 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
    


Answer: You need to add your virtual environment path so that apache/python can find
modules there.

Either put this in your apache configuration (outside of `VirtualHost` entry)

    
    
    WSGIPythonPath /home/me/virtualenv/env1/lib/python2.7/site-packages
    

Or put it in the `sys.path` in your wsgi file.

