mod_wsgi不尊重WSGIPythonHome

时间:2011-12-28 20:30:13

标签: python apache mod-wsgi

我正在尝试使用virtualenv设置运行WSGI。我的virtualenv一切正常:

(virtualenv)dev:/var/www/app$ which python
/var/www/virtualenv/bin/python
(virtualenv)dev:/var/www/app$ python
Python 2.6.1 (r261:67515, Dec  5 2008, 22:09:34)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib
>>>

在我的httpd.conf中,我有以下内容,如here所述:

WSGIPythonHome /var/www/virtualenv
WSGIPythonPath /var/www/virtualenv/lib/python2.6/site-packages

但是当我尝试通过apache加载应用程序时,我收到以下错误:

[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] mod_wsgi (pid=15026): Exception occurred processing WSGI script '/var/www/app/wsgi.py'.
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1]   File "/var/www/app/wsgi.py", line 29, in <module>
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1]     import importlib
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] ImportError: No module named importlib

我错过了什么?甚至如何调试这类问题?

1 个答案:

答案 0 :(得分:19)

您的mod_wsgi可能是针对不同于您试图强制使用的Python版本编译的。例如,您不能使用针对Python 2.4编译的mod_wsgi和使用Python 2.6构建的虚拟环境。

首先验证为什么版本的Python mod_wsgi构建。