/usr/bin/env python, force a version
Laszlo Zsolt Nagy
gandalf at designaproduct.biz
Thu Oct 6 14:53:56 CEST 2005
Roel Schroeven wrote:
>Laszlo Zsolt Nagy wrote:
>>manatlan at gmail.com wrote:
>>>I've got a trouble, and i think that anybody there can help me
>>>I've got a python script which i distribute in somes packages for *nix.
>>>This script is full of python and need python 2.4 ! And i'd like to
>>>display a message when the user doesn't have a python2.4 version.
>>'2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]'
>Yes, but the problem is also that Debian (not only Sid, but also stable
>and testing) has python 2.4 but it is not the default, i.e.
>/usr/bin/python is a symlink to /usr/bin/python2.3 even if
>/usr/bin/python2.4 is available to.
Create a list of possible locations. First of all, use your PATH, and
then add common locations:
['/bin','/usr/bin','/opt/bin','/usr/local/bin'] # etc.
Then use a list of the possible executable names:
['python','python2.3','python2.4'] # etc
Finally using these combinations, execute each executeable with
and examine its output. This may work, but I'm affraid there is no
The system administrator can install different python versions to
virtually any location.
But I don't think you should be affraid of that. If a system admin
versions into strange locations, then he will take the responsibility to
fix python programs
that need a specific version. But in most cases, looking for a python
on your PATH should be enough; and it is the most I would expect from an
- create a configuration file that resides beside your Python program
- take the path to the good executeable there
- if the program was started with the wrong version, but you have
the path to the good one (from the config file), then re-execute
- otherwise print an error message telling the required version AND
how the user can set it up in the config file
Third idea (for Windows only): read available versions from the
More information about the Python-list