bash - Portable exe-wrappers for Python scripts. In what situations will my solution not work? -
i have these wrappers python 2 , 3 scripts:
for unix-like systems:
#!/bin/sh scriptdir="$(cd "$(dirname "$0")" && pwd)" /usr/bin/env python2.7 "$scriptdir/program27.py" "$@" #!/bin/sh scriptdir="$(cd "$(dirname "$0")" && pwd)" /usr/bin/env python3 "$scriptdir/program34.py" "$@"
for windows:
@py -2 "%~dp0\program27.py" %* @py -3 "%~dp0\program34.py" %*
the scripts strictly command-line tools, , placed in same directory wrappers. there version checks inside scripts. i'm trying make sure invoked using correct python, , run on many systems , python distributions possible.
the wrappers above ones i've found work standard python distribution on windows, linux , cygwin, , darwin (and presumably bsd).
i'm beginner these things, , understand there's no perfect solution, i'm wondering if can point out in situations above won't work, , me improve on it.
thanks.
please see pep 397 information on how handle executing code in correct python interpreter on windows. on other hand, pep 394 covers similar topic when running on unix-like platforms. recent changes made in python 3.3 allow defined behavior code should executed.
pep 397: python launcher windows
the python 3.3 windows installer includes py launcher application can used launch python applications in version independent fashion.
this launcher invoked implicitly when double-clicking *.py files. if single python version installed on system, version used run file. if multiple versions installed, recent version used default, can overridden including unix-style “shebang line” in python script.
the launcher can used explicitly command line py application. running py follows same version selection rules implicitly launching scripts, more specific version can selected passing appropriate arguments (such -3 request python 3 when python 2 installed, or -2.6 specifclly request earlier python version when more recent version installed).
in addition launcher, windows installer includes option add newly installed python system path. (contributed brian curtin in issue 3561.)
in short, preface code following lines:
#! /usr/bin/env python2
python 2.x#! /usr/bin/env python3
python 3.x
Comments
Post a Comment