-   Linux - Software (
-   -   apache/mod_python problem: ImportError: No module named mod_python.apache (

BrianK 09-27-2007 05:12 PM

apache/mod_python problem: ImportError: No module named mod_python.apache
For reasons that I won't get into in this thread, I've built a webserver that runs out of my homedir (with php & sqlite to boot). Now, however, I need python, so I'm trying to build/install mod_python. To get the build to work, I needed to also build/install python, which I've done (all running out of my homedir). I can build & install mod_python fine now. I've edited my httpd.conf to load up the from my homedir.

Watching apache's logs on startup, I can see it loading up mod_python:


[Thu Sep 27 14:56:32 2007] [notice] mod_python: Creating 8 session mutexes based on 256 max processes and 0 max threads.
[Thu Sep 27 14:56:32 2007] [notice] mod_python: using mutex_directory /tmp
[Thu Sep 27 14:56:32 2007] [notice] Apache/2.2.6 (Unix) PHP/5.2.4 mod_python/3.3.1 Python/2.5.1 configured -- resuming normal operations

but when I try to load up a simple

from mod_python import apache

def handler(req):
    req.content_type = 'text/plain'
    req.write("Hello World!")
    return apache.OK

I get this message showing up in the apache logs:

[Thu Sep 27 14:56:48 2007] [error] make_obcallback: could not import mod_python.apache.\n
ImportError: No module named mod_python.apache
[Thu Sep 27 14:56:48 2007] [error] make_obcallback: Python path being used "['/usr/lib/', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/var/lib/python-support/python2.5', '/var/lib/python-support/python2.5/HTMLgen']".
[Thu Sep 27 14:56:48 2007] [error] get_interpreter: no interpreter callback found.
[Thu Sep 27 14:56:48 2007] [error] [client] python_handler: Can't get/create interpreter.

any ideas on why this is happening? Could it be that the python in my homedir is not listed in the pythong path in the above error message? If so, how do I get it in there?

FWIW, I configured mod_python like so:

./configure --prefix=$HOME/local --with-apxs=$HOME/local/bin/apxs --with-python=$HOME/local/bin/python

Any help would be much appreciated.

lucastic 09-29-2007 06:41 AM

Yes, I would say it is something to do with your python paths. Find the file

slocate mod_python (or mod_python.apache)

Then check that the file is in a directory referred to by "Python path being used"

Dont know if thats the problem but its certainly one option you could easily eliminate

BrianK 10-10-2007 05:13 PM


It was a path issue. The simple solution is to set an env var PYTHONHOME to the base of the python install (i.e. where you pointed --prefix to in the configure step).

Once that's done, in the same shell, restart apache. So, in my case, it went a little like this:


./configure --prefix=$HOME/local --with-apxs=$HOME/local/bin/apxs --with-python=$HOME/local/bin/python --with-python-src=$HOME/install/Python-2.5.1
make -j2
make test
make install
$HOME/bin/apachectl -k restart

There's probably a way of doing this inside of the apache conf (or maybe even through an htaccess override), but I don't know how to do that.

All times are GMT -5. The time now is 11:20 AM.