[mod_python] Import Issues

Mike Verdone mike_verdone at shaw.ca
Sat Apr 5 11:20:26 EST 2003

On April 5, 2003 10:53 am, Tommy !! wrote:
> Hi all,
> Just curious as to why (by design?) mod_python does not allow one to import
> modules in the same directory as the executing script - instead you have to
> resort to altering sys.path inside each script in order to get it importing
> correctly.
> This is an issue if you don't have access to the web server to modify
> httpd.conf and .htaccess files are disabled/limited. Additionally, I may
> not have access to the site-packages directory, or any other directory, for
> that matter, from which my script could import reusable components.

The main problem is that mod_python doesn't know what directory it's in when 
it executes a script except in two cases (as far as I can tell):

1. You put the AddHandler directive in the .htaccess file in that directory.

2. You enclose the AddHandler directive in a <Directory> block specifying the 
full path in apache.conf.

Otherwise mod_python has no idea where it's really executing from, and seems 
to default to the apache dir. If your administrator has restricted .htaccess 
and won't set up apache.conf for you, then you're kinda hooped.

Have you looked at the PythonPath directive? You may be able to get away with 
that in your .htacces. e.g.:

PythonPath "['/the/scripts/directory'] + sys.path"

Good luck!


More information about the Mod_python mailing list