我成功地从源代码中安装了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我得到了错误,Internet Server错误,下面是我的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。
谢谢。
发布于 2011-11-17 19:00:04
恐怕我帮不上mod_python了。我们已经将所有的代码从mod_python转向了mod_wsgi,从来没有回头看过。
mod_wsgi有一些很好的特性--更不用说轻松创建调试/诊断代码的能力,而不是完全从python上运行,而不需要运行Apache (这就打开了运行调试器的能力&直接打印到stdout)。
如果您沿着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)祝好运。
https://stackoverflow.com/questions/8163904
复制相似问题