virtualenv isolated app somehow finds global django installation instead of local one
Question:   1. I have globally installed django v1.8 on (ubuntu + apache + mod_wsgi)
  2. I have a virtualenv _'myenv'_ with --no-site-packages (which means it is isolated from global packages) with django 1.9 installed inside

here is my app's apache config

    
    
    WSGIPythonPath /var/djp/myapp:/root/.virtualenvs/myapp/lib/python2.7/site-packages
    
    <VirtualHost *:80>
    
        WSGIDaemonProcess mydomain.com python-path=/var/djp/myapp:/root/.virtualenvs/myenv/lib/python2.7/site-packages
        WSGIProcessGroup mydomain.com
        WSGIPassAuthorization On
    
        WSGIScriptAlias / /var/djp/myapp/myapp/wsgi.py
        ServerName mydomain.com
        ServerAlias *.mydomain.com
        ErrorLog ${APACHE_LOG_DIR}/myapp/myapp_error.log
        LogLevel info
    
    </VirtualHost>
    

if then i switch to myenv and check version in python i get

    
    
    >>> import django
    >>> django.VERSION
    (1, 9, 7, 'final', 0)
    >>> import sys
    >>> print sys.path 
    *the path is ok*
    

But if i open up webpage of my app i see the following

    
    
    Django Version: 1.8.3
    
    Python Executable:  /usr/bin/python
    Python Version: 2.7.3
    Python Path:    
    ['/var/djp/myapp', # - ok
     '/root/.virtualenvs/myenv/lib/python2.7/site-packages', # - ok
     '/usr/lib/python2.7', # - not ok (global)
     '/usr/lib/python2.7/plat-linux2', # - not ok (global)
     '/usr/lib/python2.7/lib-tk', # - not ok (global)
     '/usr/lib/python2.7/lib-old', # - not ok (global)
     '/usr/lib/python2.7/lib-dynload', # - not ok (global)
     '/usr/local/lib/python2.7/dist-packages', # - not ok (global)
     '/usr/lib/python2.7/dist-packages', # - not ok (global)
     '/usr/lib/python2.7/dist-packages/PIL', # - not ok (global)
     '/usr/lib/pymodules/python2.7'] 
    

I just dont get it, why it executes django 1.8 first? My local site-packages
should be found first. My first thought was, that python just couldn't find
django 1.9 in myenv. But i can easily import it from python shell as shown
above!

Here is the output of pip freeze in myenv:

    
    
    Django==1.9.7
    argparse==1.2.1
    distribute==0.6.24
    django-crispy-forms==1.6.0
    djangorestframework==3.3.3
    psycopg2==2.6.1
    wsgiref==0.1.2
    

Everything is on it's place. I have no idea what happens. Please help


Answer: Try:

    
    
    WSGIRestrictEmbedded On
    
    <VirtualHost *:80>
    
        WSGIDaemonProcess mydomain.com python-home=/root/.virtualenvs/myenv python-path=/var/djp/myapp
        WSGIProcessGroup mydomain.com
        WSGIPassAuthorization On
    
        WSGIScriptAlias / /var/djp/myapp/myapp/wsgi.py
        ServerName mydomain.com
        ServerAlias *.mydomain.com
        ErrorLog ${APACHE_LOG_DIR}/myapp/myapp_error.log
        LogLevel info
    
    </VirtualHost>
    

That is, turn off interpreter initialisation in embedded mode processes and
then use `python-home` option to say where virtual environment is.

The remaining question is whether you are using a non system Python
installation. If you are and mod_wsgi was actually compiled for system Python
and not your separate one, more work is needed.

A further issue may also be that `/root` directories are not actually readable
to Apache user.

