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

Jack Jansen Jack.Jansen@oratrix.com
Sat, 15 Feb 2003 17:16:11 +0100


On vrijdag, feb 14, 2003, at 22:13 Europe/Amsterdam, Samuel M. Smith 
wrote:

> 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']

You've managed to confuse the Python code that attempts to find 
sys.path (together with the way the fink folks built the distribution).

Python first looks at it's argv[0], which is /usr/local/bin/python in 
your case. It then removes the "bin/python" bit and appends 
"lib/python2.2". If this exists it is happy and builds sys.path from 
here.
If it doesn't exist it looks at the location where it thought it was 
going to be installed when it was built. Apparently for your fink 
python this was "/usr", so it finds the Apple-installed python lib 
directory. (Note that the actual process is much more involved, but 
this is the gist of it).

You can fix it by creating a symlink /usr/local/lib/python2.2 pointing 
to /sw/lib/python2.2. Or, even easier, you could simply put 
#!/sw/bin/python into your scripts.
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma 
Goldman -