[mod_python] sys.path

Graham Dumpleton grahamd at dscpl.com.au
Thu Aug 10 18:41:38 EDT 2006


luby liao wrote ..
> After I installed mod_python and tested it, it did not work.  I got a
> 'Internal Server' error.  The cause was that sys.path was incorrect.  I
> used
> /usr/local/bin/python2.3 to build, but sys.path did not include
> /usr/local/lib/python2.3..., instead, it included sub-directories of
> /usr/lib/python2.3.  This problem is easily fixed by setting up soft links.
> But I am curious as to how the build process determines the sys.path. 

By some strange magic that I don't even fully understand.

In short, when Python is initialised by mod_python at run time, Python does
various checks to try and work out where everything is installed and from
that setup sys.path. One of the prime ways it uses to determine this is to
look at which 'python' executable is found in the PATH of the user which
Apache is executed as. If it can't find one, it possibly falls back to some
standard defaults (not sure).

End result is that it appears that the PATH of the user that Apache runs as
does not include '/usr/local/bin' towards the head and thus doesn't find the
version of Python you actually used to build mod_python. Thus, add that
bin directory to the start of PATH for user Apache runs as or in the Apache
startup scripts, whatever may be appropriate for your platform.


Graham


More information about the Mod_python mailing list