[mod_python] PythonPath problem

Shuying Wang shuying at gmail.com
Wed Mar 30 21:11:38 EST 2005

On Tue, 29 Mar 2005 21:26:37 -0500, Graham Dumpleton
<grahamd at dscpl.com.au> wrote:
> 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

Yep. And that worked.  Although the mptest example in the
documentation that came with the package appeared to be missing the
line "req.content_type= 'text/plain'" which was required to get the
test script working. A simple CGI script which didn't import anything
but just displayed a string worked as well.

> 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

There was a log of these requests but no errors were logged.  I seem
to have progressed from a blank page however following your
suggestion. Now I get ImportError even though I've included the path
to that module via the PythonPath directive within <Directory>

> > 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?

$python_lib and $docroot expands to the actual path where the
corresponding directories are located since httpd.conf is generated by
a script.
> To help us understand, you may want to show actual pathnames for
> your document root and what these two values really are.

I've got a test environment where apache reads the configuration file
httpd.conf from a generated directory in /tmp.  $python_lib and
$docroot are directories of the python source in my home directory and
when the configuration file gets generated, points to the right

In the CGI script which has imported modules, I first had 
"import x,  y" and when that resulted in "ImportError: No module named
x", I tried
from mod_python import apache
xx =  apache.import_module("x") ...
which also gave me the same error.


More information about the Mod_python mailing list