如何更改 mod_python 使用的 python 版本

发布于 2024-08-19 00:08:27 字数 1182 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

写给空气的情书 2024-08-26 00:08:27

您必须根据 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.

幸福不弃 2024-08-26 00:08:27

不要再使用 mod_python 了。 mod_wsgi 是现在部署 Django 应用程序的推荐方法。

Don't use mod_python any more. mod_wsgi is the recommended way to deploy Django appliations now.

旧竹 2024-08-26 00:08:27

可以重建mod_python以动态链接libpython,以便您可以获取libpython的版本更新,但这需要一些诡计。

您需要按如下方式编辑 mod_python 的配置脚本(删除 -L${PyLIBPL}):

$ diff  configure.orig configure 
<   LDFLAGS="${LDFLAGS} -L${PyLIBPL}"
---
>   LDFLAGS="${LDFLAGS}"

然后执行

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}):

$ diff  configure.orig configure 
<   LDFLAGS="${LDFLAGS} -L${PyLIBPL}"
---
>   LDFLAGS="${LDFLAGS}"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文