/usr/bin/env python, force a version

Michael Ekstrand mekstran at scl.ameslab.gov
Thu Oct 6 16:09:58 CEST 2005

On Thursday 06 October 2005 06:25, manatlan at gmail.com wrote:
> I hope you understand my needs. Is there a python/bash mechanism to
> override the default python version of the system ...  and run the
> script with any version of python (but the most recent) ?
> or can you explain me how to do that ? the simplest way ?

This solution makes a few assumptions... but it should work in the 
majority of cases.

The principle is that Python is, in my experience, *usually* installed 
as python2.4 or whatever - even ./configure && make && make install in 
the tarball makes python a symbolic link to a python2.4 executable. 
Assuming that this is the case, and that python2.4 will never be any 
other version of Python:


PYTHON=`which python2.4`

if [ $? != 0 ]; then
echo "This program requires Python 2.4 to be installed." >/dev/stderr
exit 1

"$PYTHON" "$APPATH" "$@"

Problems: Requires Python 2.4 to be installed as python2.4, and doesn't 
have upward compatibility (i.e. 2.5). But it's at least as good as 
#!/usr/bin/env python2.4, and it gives a clean error message.


More information about the Python-list mailing list