Question

I was able to install apache & python successfully from source.

I installed mod_python with following configure command:

./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

I copied my test file (mptest.py) to htdocs/test folder, following is my 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

also i copied my .htaccess to htdocs/test folder, following is my .htaccess:

AddHandler mod_python .py

PythonHandler mptest

PythonDebug On

I am getting the error, Internet Server Error and following is my apache error log :

[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/

my mod_python.so is linked to system's python which i dont want, proof is below. how can i link it to python installed by me?

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 (compatibility version 1.0.0, current version 125.0.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0)

I just want to display mptest.py in my web browser, can any one help me ?

I know mod_wsgi is better option than mod_python, but I need to make mod_python work. I will try mod_wsgi later.

Thanks.

Was it helpful?

Solution

I'm afraid I can't help with mod_python. We've switched all our code away from mod_python in favor of mod_wsgi and never looked back.

mod_wsgi has some great features -- not to mention the ability to easily create debug/diagnostic code than can be run entirely from python without the trouble of running Apache (which opens the ability to run debuggers & print directly to stdout).

If you go down the path of wsgi, consider using webob for managing Request/Response objects.

Here's how you'd code your example in 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)

Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top