My python in virtual-env is 2.7 but the Django debug screen shows the system's 2.6.6
Question: So inside of my virtual env, if I activate it and type `python`, version 2.7
is opened, as it should.

When an error arises in Django, it shows version 2.6 which is the system
default. Here is what my Apache configuration looks like:

    
    
    <VirtualHost *:80>
        ServerName www.mysite.com
        ErrorLog /var/www/virtualenv-2.7/django-error-log
        Alias /static/ /var/www/virtualenv-2.7/mysite/mainapp/static/
        WSGIDaemonProcess mysite python-path=/var/www/virtualenv-2.7/mysite:/var/www/virtualenv-2.7/lib/python2.7/site-packages
        WSGIProcessGroup mysite
        WSGIScriptAlias / /var/www/virtualenv-2.7/mysite/mysite/wsgi.py
    
        <Directory /var/www/virtualenv-2.7>
        Order allow,deny
        Allow from all
        </Directory>
    </VirtualHost>
    
    WSGISocketPrefix /var/run/wsgi
    WSGIPythonPath /var/www/virtualenv-2.7/mysite:var/www/virutalenv-2.7/lib/python2.7/site-packages
    

My wsgi.py:

    
    
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

When I `service httpd restart`, this is what is put in the apache error logs:

    
    
    [Mon Jan 19 20:19:03 2015] [notice] caught SIGTERM, shutting down
    [Mon Jan 19 20:19:04 2015] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
    [Mon Jan 19 20:19:04 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
    [Mon Jan 19 20:19:04 2015] [notice] Digest: generating secret for digest authentication ...
    [Mon Jan 19 20:19:04 2015] [notice] Digest: done
    [Mon Jan 19 20:19:04 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations
    

Any idea why Django does not use 2.7 found in the virtual env?


Answer: The `mod_wsgi` module is compiled against the system version of Python; the
clue is in the startup message:

    
    
                               mod_wsgi library version
                               vvvvvvvvvvvv
    Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured
                                            ^^^^^^^^^^^^
                                            Python version
    

To fix this, you can either compile mod_wsgi against the version of Python you
need, or use the
[`WSGIPythonHome`](https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonHome)
configuration directive:

> Used to indicate to Python when it is initialised where its library files
> are installed. This should be defined where the Python executable is not in
> the PATH of the user that Apache runs as, or where a system has multiple
> versions of Python installed in different locations in the file system,
> especially different installations of the same major/minor version, and the
> installation that Apache finds in its PATH is not the desired one.
>
> **This directive can also be used to indicate a Python virtual environment
> created using a tool such as virtualenv, to be used for the whole of
> mod_wsgi.**

In your Apache configuration, add the following and then reload the server:

    
    
    WSGIPythonHome /var/www/virtualenv-2.7/lib/python2.7
    

