Configuring apache to execute python scripts using mod_python handler

Juan Carlos Rodriguez jcquevedo84 at
Fri Feb 12 18:08:59 CET 2010

I configured apache to execute python scripts using mod_python
handler. I followed below mentioned steps to configure apache.

1. In http.conf I added

  <Directory "D:/softwares/Apache2.2/htdocs">
  AddHandler mod_python .py
  PythonHandler mptest
  PythonDebug On

2. Then I added the line "LoadModule python_module modules/" to http.conf.

Then I tried execute the python script mentioned below from browser.

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

Then I am getting the following error

Traceback (most recent call last):

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "D:\softwares\Python25\Lib\site-packages\mod_python
\", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named mptest

I am using Apache 2.2.4, python 2.5 and mod_python-3.3.1.win32-py2.5-

I am able to execute python scripts by configuring apache to execute
the cgi scripts. But I want to execute it using mod_python as it is
faster compared to cgi mode. Someone please help me on this issue.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list