在Mac OS X 10.6上为Apache 2.2.21和Python 2.5.4安装mod_python
我成功地从源代码安装了Apache和Python。
我用以下配置命令安装了mod_python:
./configure --prefix=/usr/local/python/lib/python2.5/site-packages/mod_python --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python/bin/python2.5
我把我的测试文件(mptest.py)复制到了htdocs/test文件夹,下面是我的mptest:
from mod_python import apache
def handler(req):
req.log_error('handler')
req.content_type = 'text/plain'
req.send_http_header()
req.write('mptest.py\n')
return apache.OK
我还把我的.htaccess文件复制到了htdocs/test文件夹,下面是我的.htaccess:
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
我遇到了一个错误,显示“互联网服务器错误”,以下是我的Apache错误日志:
[Wed Nov 16 17:10:48 2011] [notice] mod_python: Creating 8 session mutexes based on 256 >max processes and 0 max threads.
[Wed Nov 16 17:10:48 2011] [notice] mod_python: using mutex_directory /tmp
[Wed Nov 16 17:10:48 2011] [notice] Apache/2.2.21 (Unix) PHP/5.2.17 mod_python/3.3.2-dev-20080819 Python/2.5.4 configured -- resuming normal operations
[Wed Nov 16 17:11:00 2011] [error] make_obcallback: could not import mod_python.apache.\n
ImportError: No module named mod_python.apache
[Wed Nov 16 17:11:00 2011] [error] make_obcallback: Python path being used "['/Library/Python/2.5/site-packages/setuptools-0.6c11-py2.5.egg', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload', '/Library/Python/2.5/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-unicode']".
[Wed Nov 16 17:11:00 2011] [error] get_interpreter: no interpreter callback found.
[Wed Nov 16 17:11:00 2011] [error] [client ::1] python_handler: Can't get/create interpreter., referer: http://localhost/test/
我的mod_python.so链接到了系统自带的Python,而我不想这样,下面是证明。我该如何把它链接到我自己安装的Python呢?
Mac-Pro:~ user$ otool -L /usr/local/apache/modules/mod_python.so
/usr/local/apache/modules/mod_python.so:
/System/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.4)
/usr/lib/libSystem.B.dylib(兼容版本1.0.0,当前版本125.0.0) /usr/lib/libgcc_s.1.dylib(兼容版本1.0.0,当前版本625.0.0)
我只想在我的网页浏览器中显示mptest.py,有谁能帮我吗?
我知道mod_wsgi比mod_python更好,但我需要让mod_python工作。稍后我会尝试mod_wsgi。
谢谢。
1 个回答
1
我帮不了你关于mod_python的事情。我们已经把所有代码都换成了mod_wsgi,并且再也没有回头。
mod_wsgi有很多很棒的功能——更不用说它能让你轻松创建调试和诊断代码,这些代码完全可以用Python运行,而不需要麻烦地启动Apache(这样你就可以直接运行调试工具和输出信息到标准输出)。
如果你选择使用wsgi,建议用webob来管理请求和响应对象。
下面是你在mod_wsgi中如何编写这个例子的代码
# --------- EXAMPLE ----------
from webob import Response
def application(environ, start_response):
res = Response()
res.content_type = 'text/plain'
res.body = "mptest.py\r\n"
return res(environ, start_response)
祝你好运。