[mod_python] PythonPath problem

Graham Dumpleton grahamd at dscpl.com.au
Tue Mar 29 21:26:37 EST 2005


Shuying Wang wrote ..
> Hi,
> 
> I'm new to mod_python and I have a whole bunch of legacy code to get
> running with mod_python. I've followed the manual for configuration
> and I'm getting a blank page.

Before you tried to use mod_python.cgihandler, did you first try and
get a mptest.py type example going as documented? Have you gone
through the Apache log files to see what you can find in the way of
errors or history of your actual requests etc? Did you manage to get
a simple mod_python CGI example working that didn't import anything,
but just displayed something?

> I read mod_python FAQ #2.4 but I still
> can't figure out what I'm doing wrong.
> 
> I've added the following  to my apache config file:
> LoadModule python_module /usr/lib/httpd/mod_python.so
> AddHandler mod_python .py 
> PythonHandler mod_python.cgihandler  

It is not generally good practice to enable mod_python at global scope
across a whole site. You would be better to do it within a <Directory>
directive so that it is at least limited to a part of the document tree.
Even if you do want it for the whole document tree, still use the
<Directory> directive but have the document root as what it applies
to. By doing this, that directory at least will be automatically added
to sys.path for you.

> DirectoryIndex index.py

In Apache 2, I am not sure that DirectoryIndex will actually do anything
for you as far as directing a directory access to index.py. It will if you
are using Apache 1.3 and index.py actually exists. Anyway, your mileage
may vary on this point depending on your Apache configuration and which
handler is used.

> PythonPath "sys.path + ['$python_lib', '$docroot']"
> ...
>
> $python_lib and $docroot are 2 sub-directories in the current
> directory and files in $docroot requires packages in $python_lib to
> work.  If I do not use the PythonPath directive, I  get "ImportError:
> No module named x" where x is a module in $python_lib.

Are '$python_lib' and '$docroot' mean't to be indicative only of your
actual pathnames or is this actually what you are setting them to?

To help us understand, you may want to show actual pathnames for
your document root and what these two values really are.

Graham


More information about the Mod_python mailing list