[mod_python] apache2 won't load mod_python (still)

Dave Britton dave at davebritton.com
Tue Mar 22 17:38:19 EST 2005

Robert wrote:
> Is _apache.py in /usr/local/lib/python2.3/site-packages/mod_python? If 
> not, that's the problem. Clean the mod_python source directory and try 
> installing it again. If it is there, check sys.path. Is 
> /usr/local/lib/python2.3/site-packages in it?
I did this re-build (again, carefully),  and the server is still failing...

  I don't think that the mod_python setup actually creates _apache.py. Isn't 
that supposed to be the DSO callback into apache itself that links python 
into apache? Here's what I get after cleaning the mod_python directory out 
and redoing config, install and make install: Make outputs:
[root at ap1 mod_python-3.1.4]# make install
make[1]: Entering directory `/usr/local/mod_python-3.1.4'
make[2]: Entering directory `/usr/local/mod_python-3.1.4/src'
make[2]: Leaving directory `/usr/local/mod_python-3.1.4/src'
make[2]: Entering directory `/usr/local/mod_python-3.1.4/dist'
make[3]: Entering directory `/usr/local/mod_python-3.1.4/src'
make[3]: `psp_parser.c' is up to date.
make[3]: Leaving directory `/usr/local/mod_python-3.1.4/src'
/usr/local/bin/python setup.py build
running build
running build_py
running build_ext
make[2]: Leaving directory `/usr/local/mod_python-3.1.4/dist'

Now su and make install
  (or, if you only want to perform a partial install,
   you can use make install_dso and make install_py_lib)

Performing DSO installation.

/usr/bin/install -c -d /usr/local/apache2/modules
/usr/bin/install -c src/mod_python.so /usr/local/apache2/modules
make[2]: Entering directory `/usr/local/mod_python-3.1.4'
cd dist && make install_py_lib
make[3]: Entering directory `/usr/local/mod_python-3.1.4/dist'
make[4]: Entering directory `/usr/local/mod_python-3.1.4/src'
make[4]: `psp_parser.c' is up to date.
make[4]: Leaving directory `/usr/local/mod_python-3.1.4/src'
if test -z "" ; then \
        /usr/local/bin/python setup.py install --optimize 2 --force ; \
else \
        /usr/local/bin/python setup.py install --optimize 2 --force --root 
; \
running install
running build
running build_py
running build_ext
running install_lib
creating /usr/local/lib/python2.3/site-packages/mod_python
copying build/lib.linux-i686-2.3/mod_python/cgihandler.py -> 
copying build/lib.linux-i686-2.3/mod_python/Cookie.py -> 
copying build/lib.linux-i686-2.3/mod_python/util.py -> 
copying build/lib.linux-i686-2.3/mod_python/publisher.py -> 
copying build/lib.linux-i686-2.3/mod_python/__init__.py -> 
copying build/lib.linux-i686-2.3/mod_python/apache.py -> 
copying build/lib.linux-i686-2.3/mod_python/psp.py -> 
copying build/lib.linux-i686-2.3/mod_python/Session.py -> 
copying build/lib.linux-i686-2.3/mod_python/_psp.so -> 
/usr/local/lib/python2.3/site-packages/mod_python/cgihandler.py to 
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/Cookie.py 
to Cookie.pyc
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/util.py to 
/usr/local/lib/python2.3/site-packages/mod_python/publisher.py to 
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/__init__.py 
to __init__.pyc
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/apache.py 
to apache.pyc
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/psp.py to 
byte-compiling /usr/local/lib/python2.3/site-packages/mod_python/Session.py 
to Session.pyc
writing byte-compilation script '/tmp/tmpuJI-72.py'
/usr/local/bin/python -OO /tmp/tmpuJI-72.py
removing /tmp/tmpuJI-72.py
make[3]: Leaving directory `/usr/local/mod_python-3.1.4/dist'
make[2]: Leaving directory `/usr/local/mod_python-3.1.4'

Now don't forget to edit your main config and add
    LoadModule python_module /usr/local/apache2/modules/mod_python.so
and if your configuration uses ClearModuleList, then also
    AddModule mod_python.c

make[1]: Leaving directory `/usr/local/mod_python-3.1.4'
[root at ap1 mod_python-3.1.4]#
python sys.path reports:
[root at ap1 python2.3]# python
Python 2.3.3 (#1, May 18 2004, 02:14:01)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/local/lib/python23.zip', '/usr/local/lib/python2.3', 
'/usr/local/lib/python2.3/plat-linux2', '/usr/local/lib/python2.3/lib-tk', 
So, you see there is an apache.py, but no _apache.py. Everything else calls 
apache.py which then fails when it tries to load _apache.py - apache can't 
load the dso module.
I removed the apache2 and mod_python directories and rebuilt everything from 
using the apache configure:
./configure --enable-mods-shared --enable-so --enable-python=shared
and mod_python:
./configure --with-apxs=/usr/local/apache2/bin/apxs
In the httpd.conf file I have:

LoadModule python_module /usr/local/apache2/modules/mod_python.so
(which file is in the right place: -rwxr-xr-x    1 root     root 
4093859 Mar 22 22:46 mod_python.so)

<Directory /usr/local/apache2/htdocs>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On

and still get this error message when I browse to 
(taken from the error log, from the point of server startup:)
[Tue Mar 22 23:12:41 2005] [notice] mod_python: Creating 25 session mutexes 
based on 25 max processes and 0 max threads.
[Tue Mar 22 23:12:41 2005] [notice] Apache/2.0.53 (Unix) mod_python/3.1.4 
Python/2.3.3 configured -- resuming normal operations
[Tue Mar 22 23:12:41 2005] [info] Server built: Mar 16 2005 19:13:58
[Tue Mar 22 23:12:41 2005] [debug] prefork.c(956): AcceptMutex: sysvsem 
(default: sysvsem)
[Tue Mar 22 23:15:31 2005] [error] make_obcallback: could not import 

What could be wrong?


More information about the Mod_python mailing list