Mod wsgi 没有在 Arch linux 上使用 virtualenv python 版本

Mod wsgi not using virtualenv python version on Arch linux

我在 Arch linux 服务器上的 apache-python2(virtualenv)-flask 堆栈上有一个网站 运行。似乎 wsgi 应用程序没有从 virtualenv 中获取 python,而是使用系统的 python.

web/test.py

import sys
print(sys.version)

结果:error_log

3.4.3 (default, Mar 25 2015, 17:13:50)

服务器上的默认 python 是

$ python --version
Python 3.4.3

我打算使用的虚拟环境有python2

$ virtualenv -p /usr/bin/python2.7 flask
$ source flask/bin/activate
$ python --version
Python 2.7.10

虚拟主机 apache 文件: /etc/httpd/conf/vhosts/msw.com

<VirtualHost *:80>
    ServerName msw.com
    ServerAlias www.msw.com
    ServerAdmin webmaster@localhost
    WSGIDaemonProcess msw user=live group=live threads=5 python-path=/home/live/msw/flask/lib/python2.7/site-packages
    WSGIScriptAlias / /home/live/msw/msw.wsgi

    <Directory /home/live/msw>
            #Header set Access-Control-Allow-Origin "*"
            WSGIScriptReloading On
            WSGIProcessGroup msw
            WSGIApplicationGroup %{GLOBAL}
            WSGIPassAuthorization On
            Options All
            AllowOverride All
            Require all granted
    </Directory>
</VirtualHost>

wsgi 文件: /home/live/msw/msw.wsgi

import sys

activate_this = '/home/live/msw/flask/bin/activate_this.py'
#execfile(activate_this, dict(__file__=activate_this))
with open(activate_this) as f:
    code = compile(f.read(), activate_this, 'exec')
    exec(code, dict(__file__=activate_this))

    sys.path.insert(0, '/home/live/msw/web')
    sys.path.insert(0, '/home/live/msw')

    from web import msw as application

为什么 mod_wsgi 没有获取 virtualenv 的 python?我做错了什么?

我终于明白了。官方 arch-linux 文档有点混乱, mod_wsgi。它试图暗示 mod_wsgi 安装对两个 Python2/3 都有效。然而,mod_wsgi 仍然最终使用系统的 Python3。我通过安装特定于 Python2.

的 mod_wsgi2 解决了这个问题
pacman -S mod_wsgi2