pythonbrew 没有被mod_wsgi文件拾取,配置如下:
import os
import sys
import site
site.addsitedir('/home/bharal/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages')
sys.path.append ('/home/bharal/public_html/dumpstown')
os.environ['DJANGO_SETTINGS_MODULE'] = 'dumpstown.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我想使用的 Python 的 pythonbrew 版本位于这里:
/home/bharal/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages
我的 pythonbrew 安装在这里:
/home/bharal/.pythonbrew/
如何告诉mod_wsgi使用此版本(2.7.2)而不是 ubuntu (2.6) 附带的默认 python 版本?
当我运行我的服务器时,我收到如下错误:
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] mod_wsgi (pid=18694): Exception occurred processing WSGI script '/home/bharal/public_html/dumpstown/dumpstown/apache/dumpstown.wsgi'.
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] self.load_middleware()
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 276, in __getattr__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] self._setup()
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 42, in _setup
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] self._wrapped = Settings(settings_module)
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 89, in __init__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'dumpstown.settings' (Is it on sys.path?): No module named gravatar.templatetags
从日志中可以看出,服务器仍在查看 Python 2.6!!为什么?我已经启动了pythonbrew,所以当我输入python
时,我可以看到版本是2.7.2,我需要的所有设置和包都是可导入的!
更新 如下面的答案所示,mod_wsgi不在乎我告诉它使用哪个python - 事实上,我不能告诉它使用任何特定的python。唯一的方法是下载一个未编译的 wsgi 文件,使用我想要的特定 python 版本进行编译,并使用编译的 wsgi。
请参阅我的另一个问题错误:使用 rc=65536 python 命令失败,如果您愿意,可以mod_wsgi一些步骤和指向 tutes 的链接。最后我没有针对 2.7 进行编译(我的 2.6 很好,而且很难让 pythonbrew 编译工作)
该特定错误与所使用的Python版本无关。用:
sys.path.append ('/home/bharal/public_html') sys.path.append ('/home/bharal/public_html/dumpstown')
要让mod_wsgi使用特定版本,请根据该版本的源代码编译它,或者找到一个二进制包,以便mod_wsgi针对正确的版本进行编译。