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,所以当我输入时,python
我可以看到版本是 2.7.2,并且我需要的所有设置和包都是可导入的!
更新如下面的答案所示,mod_wsgi不在乎我告诉它使用哪个 python - 事实上,我不能告诉它使用任何特定的 python。这样做的唯一方法是下载一个未编译的 wsgi 文件,使用我想要的特定 python 版本进行编译,然后使用已编译的 wsgi。
如果您愿意,请参阅我的另一个问题Error: Command failed with rc=65536 python and mod_wsgi了解一些步骤和指向 tutes 的链接。最后我没有针对 2.7 进行编译(我的 2.6 很好,让 pythonbrew 编译工作太难了)