[mod_python] CWD in PythonPath

Graham Dumpleton grahamd at dscpl.com.au
Wed Jan 19 21:26:31 EST 2005


Simon Kesenci wrote ..
> There doesn't appear to be a way to put the current working directory 
> in the path using the PythonPath directive.  It does fine when a module
> in the directory in question is named in a handler directive when 
> PythonPath is not set.  But when I do set PythonPath, it can only pick
> up modules in directories explicitly named in the path.
> 
> I currently have
> PythonPath "sys.path + ['/home/www/import']"
> as the directive, but I have also tried expanding sys.path out in the 
> directive with both '' and '.'.  Still not luck.

It is always a bit hard to know what people are trying to achieve when
they start talking about import problems, but you might look at the
method:

  apache.import_module()

One of the possible arguments to it is the search path to use. Ie.,
overrides sys.path. You could therefore construct a path which
includes sys.path and any other place you want to look just for that
import.

Be warned though that import_module() has its problems as well,
but it is the only other option in mod_python at the moment. Some
other packages provide their own module import mechanisms to
get around some of its shortcomings, but whether they may be
appropriate is going to be dependent on what you are trying to
do and what handler mechanisms you may or may not be using, eg.
PSP, mod_python.publisher etc.

Graham


More information about the Mod_python mailing list