An implementation of the py command for UNIX-based platforms
(with some potential experimentation for good measure 😉)
The goal is to have py become the cross-platform command that all Python users
use when executing a Python interpreter. By having a version-agnostic command
it side-steps the "what should the python command point to?" debate by
clearly specifying that upfront (i.e. the newest version of Python that can be
found). This also unifies the suggested command to document for launching
Python on both Windows as UNIX as py which has existed as the preferred
command on Windows for
some time.
See the top section of py --help for instructions.
Please note that while searching, the search for a Python version can become more specific. This leads to a switch in the search algorithm to the one most appropriate to the specificity of the version.
You can always run the Python Launcher with PYVENV_DEBUG set to some value
to have it output logging details of how it is performing its search.
- Search
PATHforpython3.6
- Check for the
PY_PYTHON3environment variable, and if defined and not the empty string then use it as the specific version (e.g.PY_PYTHON3=3.6) - Search
PATHfor all instances ofpython3.* - Find the executable with the newest version number that comes earliest on
PATH
- Use
${VIRTUAL_ENV}/bin/pythonimmediately if available - If the first argument is a file path ...
- Check for a shebang
- If shebang path starts with
/usr/bin/python,/usr/local/bin/python,/usr/bin/env pythonorpython, proceed based on the version found on that path (barepythonis considered the equivalent of not specifying a Python version)
- Check for the
PY_PYTHONenvironment variable, and if defined then use it as the loose or specific version (e.g.PY_PYTHON=3orPY_PYTHON=3.6) - Search
PATHfor all instances ofpython*.* - Find the executable with the newest version that is earliest on
PATH
NOTE: I am using this project to learn Rust, so please don't be offended if I choose to implement something myself instead of accepting a pull request that you submit. (Pull requests to do something I have already implemented in a more idiomatic fashion are very much appreciated, though.)