[mod_python] mod_python 3.3 importer with "import" statement

Graham Dumpleton graham.dumpleton at gmail.com
Fri Jun 1 03:58:14 EDT 2007

FWIW, I cover a range of issues such as Apache user permissions,
environment variables, working directories etc in:


This discussion is in relation to mod_wsgi, but many of the same
issues apply to mod_python.

Also worth a read if you haven't done so before is:


Finally, plugging mod_wsgi once more, information about web.py:


Some comments in there about how web.py intercepts 'print' are also
relevant to mod_python as use of 'print' for debugging can cause
interference with web.py.


On 01/06/07, Ben Hoyt <ben at micropledge.com> wrote:
> > By default VirtualHosts use distinct Python interpreter instances.
> Thanks for that, Graham. That stuff about Python interpreter instances was
> really helpful, and started us hunting down the right track. Anyway, the
> problems we were having were caused by:
> 1) Moving/renaming our root code directory without deleting the *.pyc files.
> I think this was adding to the confusion because we were seeing some path
> strings from the .pyc files in the error messages.
> 2) Using mod_python 3.3 on our development servers and something older on
> our live one. I think this was confusing us with regard to the import
> problem and PythonPath.
> 3) Relying on relative paths in a few places in our actually (actually in
> web.py's template handling, which we're using). We used os.chdir() to set
> the current working directory, but of course (we realise now) that the cwd
> is process-dependent rather than Python-interpreter dependent. So depending
> on which process Apache picked, it'd use the other virtual host's template
> directory and confuse everyone. I think I'll tell the web.py people that
> depending on relative paths is pretty much a bug (at least with mod_python
> -- maybe that's why they haven't seen the bug).
> Anyone else using mod_python with web.py, just out of curiosity?
> Anyway, it's fixed, and I've got my head around PythonInterpreter and
> PythonPath and various other things now. Cheers!
> > Overriding import is more complicated than just replacing __import__. ;-)
> I suspected that was the case. Looks like you've been there and done that.
> Thanks,
> Ben
> --
> Ben Hoyt, +64 21 331 841
> http://www.benhoyt.com/

More information about the Mod_python mailing list