Given a set of python programs:
/tool/a.py
/tool/b.py
/tool/c.py
/tool/d.py
...
that are stored in a shared network directory, executed in a mixed environment (Solaris and different flavors of Linux) and that all requires a specific python version that may not be in the users $PATH and may not be installed in the same location on the different types of machines.
How can the programs specify what python interpreter to use?
Alternatives I’ve considered:
-
A shebang in each python program, refereeing to a python wrapper that starts an appropriate python interpreter for the current type of machine. But execve does not allow the wrapper executable to be implemented as a shell script and compiling native executables for each machine would require a lot of maintenance.
-
Making a startup shell script for each python program. All the shell scripts may share the same logic for choosing a python interpreter, but I would like to avoid having a separate shell script for each python program, if possible.
-
Making some kind of hack to make each program possible to run both both as a shell script and a python program, similar to:
"""exec" /tool/python_wrapper "$0" "$@" """#" def foo(): print "foo" foo()
Do you have some other ideas?
I would go with option 3. It will have a small startup delay, but it is the most flexible option.
One would not work, since you are running in mixed environments it will be a nightmare to set everything up correctly.
Would work but, as you said you’ll need to maintain both the .py program and the shell script. Also it is not much different then 3.