[mod_python] Adding the current directory to the import path

Graham Dumpleton grahamd at dscpl.com.au
Sat Aug 19 03:58:21 EDT 2006


On 19/08/2006, at 5:45 PM, Max Luebbe wrote:

> I've been having a problem in mod_python with importing modules that I
> have written that aren't in the standard python libraries.
>
> If i test my code in a normal python environment, everything works  
> great
> - however when I try it out in mod_python i get import errors, and it
> does not want to locate my custom modules. What makes it weirder is  
> that
> my folder with authentication set up as an apache directive, lets me
> import custom modules from the folder, but my regular folder for  
> holding
> my scripts wont.
>
> How do I add the current directory to the import search path?
> Is this what I should be doing?
>
> I'm trying to take advantage of some code reuse, and it would be great
> if somebody has any ideas on what has been a huge annoyance to me.

There are various problems with module import in currently available  
versions
of mod_python. See:

   http://www.dscpl.com.au/articles/modpython-003.html

for further details.

Most of the issues will be addressed in mod_python 3.3.

There are two ways you can get around the problem. Not sure which is  
most
appropriate given your circumstances.

First is to use PythonPath directive to specify extra directories to  
search. This
is the same as setting PYTHON_PATH environment variable for command
line Python.

Second is to use the apache.import_module() function to import modules,
specifying a path argument of directories to search. Ie.,

   module = apache.import_module("name", path=['/some/path'])

Check the mod_python documentation.

Sorry for brief reply, in a rush.


Graham


More information about the Mod_python mailing list