Feb-21-2018, 08:58 AM
(This post was last modified: Feb-21-2018, 08:58 AM by Gribouillis.)
Here is my new bash script on this problem: it runs two python processes one after the other. The first process uses the default python interpreter. Its role is to examine the file system in order to find the best available python interpreter.
The second script runs with the best python interpreter found, and replaces the current process.
The second script runs with the best python interpreter found, and replaces the current process.
#!/bin/bash # run first python script with default python, selects best interpreter PYINTERP=$(python -c "import sys; exec(sys.stdin.read())" << GETPYTHON import sys def candidates(): yield '/usr/bin/python3' yield '/usr/local/bin/python3' yield '/usr/bin/python' yield '/usr/bin/python2' yield '/usr/local/bin/python2' yield sys.executable import os for p in candidates(): if os.path.exists(p): print(p) break GETPYTHON ) # run second python script with interpreter found, replacing current process exec $PYINTERP -c "import sys; exec(sys.stdin.read())" << PYTHONSCRIPT import sys def hi(): print('Interpreter found:', sys.executable) print('hello world') hi() PYTHONSCRIPT