[mod_python] Installation problems

Ian Clelland ian at veryfresh.com
Thu Mar 21 03:16:59 EST 2002

I believe that your problems stem from the fact that you are trying to 
use mod_python as if it was a 'traditional' scripting language like PHP 
or ASP.

With either of those languages, you can simply write scripts with the 
appropriate extensions, place them in a web-accessable directory, and 
they're automatically executable.

With mod_python, you are actually writing Apache modules in the python 
language. You need to use Apache directives to configure those modules 
to be activated at the appropriate times.

Depending on how you want to do things, I see two ways to get your test 
script to run:

1) Install the script as a handler. This is the closest to what you are 
   currently doing. The problem is that Python cannot find your module. 
   You can just add the line

     PythonPath "sys.path+['/usr/local/httpd/htdocs/test']"

   to your <Directory> entry, and the module should load.

2) Use the supplied Publisher handler (check the tutorial at 
   www.modpython.org). This is a great hack which allows a single 
   handler to load .py files from anywhere in your site. It appears to 
   be closer to what you intended to do, which is to just run a .py 
   file out of a URL.

I hope that helps clear things up.

A couple of quick points about your original email:

> /test/mptest.py  - I am asked what program to use to execute this file
This is because you have associated a MIME type with the .py extension, 
and Apache doesn't know what to do with it. (The mod_python module 
doesn't deal with MIME types like mod_php). The only thing it can do is 
offer the file for download.

> /test/mptest      - lists the ASCII source of the file
In this case, Apache's content negotiation is finding the best match 
for /mptest and returning that to you as a text document.

>     <IfModule mod_python.c>
>     AddType application/x-httpd-py .py
>     </IfModule>
This section is unnecessary, and should probably be deleted.

> PYTHONPATH:	/usr/lib/python2.1:/usr/lib/python2.1/plat-linux2:
> /usr/lib/python2.1/lib-tk:/usr/lib/python2.1/lib-dynload:/usr/lib/
> python2.1/site-packages:/usr/lib/apache/lib/python/site-packages
This variable shows the locations where Python will look for modules 
when you use an import statement (or a Python*Handler directive). Since 
/usr/local/httpd/htdocs/test is not in the list, Python cannot find 
your mptest module.

<ian at veryfresh.com>

More information about the Mod_python mailing list