[Pythonmac-SIG] python module search path in Apache on OSX

SamuelM.Smith SamuelM.Smith
Fri, 14 Feb 2003 14:13:49 -0700


I have OSX 10.2.3 with fink python 2.2.2 installed in /sw and sym links 
in /usr/local/bin
and the default apple python 2.2.0 in /usr/bin.

For cgi scripts I put #!/usr/local/bin/python as the first line of the 
file so that is runs 2.2.2 or
so I assume.

However when I run a python cgi script using the default Apache 1.3 
that comes with OSX I get the following value for sys.path once the 
script is running:

['/Users/smithsm/Sites/ht/cgi-bin', '/usr/lib/python2.2', 
'/usr/lib/python2.2/plat-darwin', '/usr/lib/python2.2/lib-tk', 
'/usr/lib/python2.2/lib-dynload', '/usr/lib/python2.2/site-packages']

It looks like apache is making my script use the modules for python 2.2 
while running 2.2.2

I realize that I can import sys and then insert the correct path which 
should be

['', '/Users/smithsm/Sites/ht/cgi-bin', '/sw/lib/python2.2', 
'/sw/lib/python2.2/plat-darwin', '/sw/lib/python2.2/lib-tk', 
'/sw/lib/python2.2/lib-dynload', '/sw/lib/python2.2/site-packages', 
'/sw/lib/python2.2/site-packages/Numeric', 
'/sw/lib/python2.2/site-packages/PIL']

but that still annoys me that I must first import the sys module of 2.2 
in order to change the import
path. although unlikely it begs the question what if the sys module of 
version 2.2 is not compatible with version 2.2+. Seems like a potential 
for problems.

Is there any other way to get the path to be the correct one a priori 
for Apache run cgi scripts?

Would putting a .pth file in my cgi-bin directory with the path work? 
The docs say add path but I need to insert path before the default.

I do not have much experience with Apache but I have modified the 
httpd.conf file on occasion. Is there some directive that would make 
apache use the right path?

What about mod_python?

thanks for any help or suggestions.

Sam