I'm trying to run Python within a sandbox using WSGI and Apache.
I created the virtual environment:
virtualenv /var/www/demo-environment --python /usr/bin/python3.3I also created the following
/var/www/demo.pyfile:#!/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)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?
1 Answer 1
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', ...
3 Comments
WSGIPythonHome, Apache doesn't respond to browser requests and is stuck with "ImportError: No module named site" warning added to error.log once per second before even the first request.