[mod_python] __import__ error

Detmar Meurers dm at julius.ling.ohio-state.edu
Mon Jun 12 21:34:17 EDT 2006

Hi Graham (et al.),

related to where you write:

    When import in mod_python is done, it will not necessarily look
    in current working directory anyway. You need to add directory
    to Python PATH explicitly using the directive:
    PythonPath 'sys.path+["/var/www-studio/"]'
    in your Apache configuration for where you are using mod_python.
I was wondering about the motivation for adding this as part of the
Apache configuration and whether there are alternatives. As
motivation for this question: During development, I have various
versions of code checked out (from cvs) to different directories, so
it's rather impractical to add each such directory to the Apache

Instead, I call sys.path.append(dirname(__file__)) in each .py file
that's in a directory from which I want to import other code (or
actually sys.path.append(join(dirname(__file__), 'include')) since I
store other python modules in an include subdirectory).

As far as I can tell, this seems to work (i.e., I can then use
import or apache.import_module to load files from those directories)
but several replies on this topic only mention the PythonPath
solution in the apache configuration, which made me wonder whether
there are downsides to using sys.path.append in the python code for


Detmar Meurers, Associate Professor, Dept. of Linguistics, OSU
201a Oxley Hall, 1712 Neil Avenue, Columbus OH 43210-1298, USA
http://ling.osu.edu/~dm/                 GnuPG key on web page

More information about the Mod_python mailing list