index.wsgi not finding virtualenv in root
Question: I am trying to install a django site on an Apache VPS, following this
[tutorial](http://thecodeship.com/deployment/deploy-django-apache-virtualenv-
and-mod_wsgi/)  
my index.wsgi should activate a virtualenv in the root, it looks like this:

    
    
    import os
    import sys
    import site
    
    # Add the site-packages of the chosen virtualenv to work with
    site.addsitedir('~/.virtualenvs/DBENV/local/lib/python2.7/site-packages')
    
    # Add the app's directory to the PYTHONPATH
    sys.path.append('/home/DB2015/')
    sys.path.append('/home/DB2015/davidcms/')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'davidcms.settings'
    
    # Activate your virtual env
    activate_env=os.path.expanduser("~/.virtualenvs/DBENV/bin/activate_this.py")
    execfile(activate_env, dict(__file__=activate_env))
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

and I get this error

    
    
    [Tue Feb 17 07:13:30.701511 2015] [:error] [pid 16103:tid 140396130674432]           [client 217.44.75.146:58169]     execfile(activate_env, dict(__file__=activate_env))
    [Tue Feb 17 07:13:30.701653 2015] [:error] [pid 16103:tid 140396130674432] [client 217.44.75.146:58169] IOError: [Errno 2] No such file or directory: '/var/www/.virtualenvs/DBENV/bin/activate_this.py'
    

So its looking in `var/www/` instead of the root. When I try to change
`os.path.expanduser` to just the path to .virtualenvs in the root as such:

    
    
    # Activate your virtual env
    activate_env= "~/.virtualenvs/DBENV/bin/activate_this.py"
    execfile(activate_env, dict(__file__=activate_env))
    

it still says

    
    
    [Tue Feb 17 07:17:12.019641 2015] [:error] [pid 16104:tid 140396206208768] [client 217.44.75.146:58200]     execfile(activate_env, dict(__file__=activate_env))
    [Tue Feb 17 07:17:12.019852 2015] [:error] [pid 16104:tid 140396206208768] [client 217.44.75.146:58200] IOError: [Errno 2] No such file or directory: '~/.virtualenvs/DBENV/bin/activate_this.py'
    

What am I missing?!


Answer: Presumably Apache is not running as you, but as its own user, so it won't use
your home directory.

You shouldn't really have your code in a home directory anyway. Pick a
standard place - eg a new top-level directory like `/srv`, or `/var/sites`, or
something.

