我正在尝试使用WSGI和Apache在沙箱中运行Python。
我创建了虚拟环境:
virtualenv /var/www/demo-environment --python /usr/bin/python3.3
我还创建了以下/var/www/demo.py
文件:
#!/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)
最后,我更改了Apache配置:
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
当访问网站的主页时,它显示以下内容:Running sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0)
,表示虽然Python有效,但它不会在虚拟环境中调用。
由于这是启用virtualenv
的错误方法,这是正确的吗?
答案 0 :(得分:1)
只需使用设置WSGIPythonHome
指定env的根目录:
WSGIPythonHome /home/grapsus/work/python/env
WSGIScriptAlias /demo /home/grapsus/work/python/demo.py
我修改了您的脚本以打印sys.path
:
Running ['/home/grapsus/work/python/env/lib/python2.7', ...