Question

I'm trying to run Python within a sandbox using WSGI and Apache.

  1. I created the virtual environment:

    virtualenv /var/www/demo-environment --python /usr/bin/python3.3
    
  2. I also created the following /var/www/demo.py file:

    #!/usr/bin/env python
    
    import sys
    
    def application(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        return "Running " + str(sys.version_info)
    
  3. Finally, I changed Apache configuration like this:

    WSGIPythonPath /var/www/demo-environment/lib/python3.3/site-packages/
    WSGIDaemonProcess example.com python-path=/var/www/demo-environment/lib/python3.3/site-packages/
    WSGIProcessGroup example.com
    WSGIScriptAlias / /var/www/demo.py
    

When going to the home page of the website, it shows the following contents: Running sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0), indicating that while Python works, it is not called within a virtual environment.

Since this is the wrong way to enable virtualenv, which is the right one?

Was it helpful?

Solution

Just use the setting WSGIPythonHome to specify the root of your env:

WSGIPythonHome /home/grapsus/work/python/env
WSGIScriptAlias /demo /home/grapsus/work/python/demo.py

I modified your script to print sys.path:

Running ['/home/grapsus/work/python/env/lib/python2.7', ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top