avoiding long paths to interpreter

holger krekel pyth at devel.trillke.net
Thu Jan 9 07:20:35 EST 2003


Erik Max Francis wrote:
> Mike Meyer wrote:
> 
> > The recommended approach is to use:
> > 
> > #!/usr/bin/env python
> > 
> > which will find python no matter where it is if it's in the users
> > path.
> 
> To be pedantic, you've no guarantee that env will be in /usr/bin
> (although granted that it will be the vast majority of the time).  The
> real wart here is that if you have multiple interpreters installed, say,
> in /usr/bin and /usr/local/bin, then /usr/bin/env picks the python
> that's associated with your PATH. 

Right that's the problem. 

> This can lead to bad surprises if the
> script runs in an interactive shell vs., say, a CGI script or a cron
> job, where the PATHs are almost certain to be far more restrictive,
> particularly if you have a highly customized interactive shell.
> 
> Unfortunately, there's truly no magic bullet here when the script itself
> depends on a certain version of Python.

Probably right, although one could try putting the below into
a file:
------------------------------------------------------------
#!/bin/sh

# find a specific python version you want to use from
# e.g. scanning PATH contents
# but i am far too lazy to write shell scripts now
# so i shortcut :-)
python=/usr/bin/python

$python <<__HERE__

import sys
sys.stdout.write("hello world from python bootstrapping code\n")

__HERE__
------------------------------------------------------------

Of course you have to find a reasonable subset of shell-commands
which is beyond me today :-)

regards,

    holger





More information about the Python-list mailing list