pythonbrew与mod_wsgi

时间:2012-07-04 02:51:58

标签: pythonbrew

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()

我想要使用的pythonbrew版本的python位于:

  

/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所以当 i 输入python时,我可以看到版本是2.7.2,我需要的所有设置和包都是可导入的!

UPDATE ,如下面的答案所示,mod_wsgi不关心哪个python我告诉它使用 - 事实上,我不能告诉它使用任何特定的python。唯一的方法是下载一个未编译的wsgi文件,使用我想要的特定python版本进行编译,并使用已编译的wsgi。

如果您愿意,请参阅我的其他问题Error: Command failed with rc=65536 python and mod_wsgi了解一些步骤和指向tutes的链接。最后我没有编译反对2.7(我的2.6很好,而且很难让pythonbrew编译工作)

1 个答案:

答案 0 :(得分:1)

该特定错误与所使用的Python版本无关。使用:

sys.path.append('/ home / bharal / public_html')   sys.path.append('/ home / bharal / public_html / dumpstown')

要使mod_wsgi使用特定版本,请根据该版本从源代码编译它,或者找到针对正确版本编译的mod_wsgi的二进制包。