如何更改 mod_python 使用的 python 版本
我正在使用 django 进行一些介绍性工作,到目前为止,这看起来非常简单(而且有趣),但是我一直在安装在 /opt/local (RedHat 5.3) 中的 Python 2.6 中完成所有这些工作,因为 redhat 附带的 python 是 2.4 。我设置了一个符号链接:
/usr/bin/python2.6 -> /opt/local/bin/python
到目前为止我一直在使用它来处理所有 django 的东西;但是
> python2.6 manage.py runserver
,当我尝试进入生产模式时,mod_python 没有使用正确版本的 python:
Mod_python error: "PythonHandler django.core.handlers.modpython"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
log=debug)
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 461, in import_module
f, p, d = imp.find_module(parts[i], path)
ImportError: No module named django
我的 /etc/httpd/conf/httpd.conf 中有这个:
<Location "/chat">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE chat.settings
PythonDebug On
PythonPath "['/www/django/chat', '/opt/local/lib/python2.6/site-packages/django/'] + sys.path"
</Location>
所以我的问题是,如何制作 mod_python寻找 python2.6 而不是 python?
I'm doing some introductory work with django which seems really easy (and fun) so far but I have been doing all this from Python 2.6 which I installed in /opt/local (RedHat 5.3) because the python that came with redhat was 2.4. I set up a symlink:
/usr/bin/python2.6 -> /opt/local/bin/python
and I have been using that for all the django stuff so far; i.e.
> python2.6 manage.py runserver
However, when I try to move on to production mode, mod_python isn't using the right version of python:
Mod_python error: "PythonHandler django.core.handlers.modpython"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
log=debug)
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 461, in import_module
f, p, d = imp.find_module(parts[i], path)
ImportError: No module named django
I have this in my /etc/httpd/conf/httpd.conf:
<Location "/chat">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE chat.settings
PythonDebug On
PythonPath "['/www/django/chat', '/opt/local/lib/python2.6/site-packages/django/'] + sys.path"
</Location>
So my question is, how do I make mod_python look for python2.6 instead of python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须根据 python2.6 安装重建 mod_python。由于 mod_python 将 python 作为库加载,因此版本在编译时是固定的。
You would have to rebuild mod_python against your python2.6 installation. Since mod_python loads python as a library the version is fixed at compile time.
不要再使用 mod_python 了。 mod_wsgi 是现在部署 Django 应用程序的推荐方法。
Don't use mod_python any more. mod_wsgi is the recommended way to deploy Django appliations now.
您可以重建mod_python以动态链接libpython,以便您可以获取libpython的版本更新,但这需要一些诡计。
您需要按如下方式编辑 mod_python 的配置脚本(删除 -L${PyLIBPL}):
然后执行
configure --with-python=/path/to/bin/python ;制作;让安装跳舞。
当您运行:
ldd mod_python.so
时,您应该看到类似以下的行:
libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0
You can rebuild mod_python to link against libpython dynamically so that you can pick up version updates to your libpython but it takes some chicanery.
You will need to edit the configure script for mod_python as follows (remove -L${PyLIBPL}):
Then do
configure --with-python=/path/to/bin/python ; make; make install dance.
When you run:
ldd mod_python.so
you should see a line that looks like:
libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0