Python launcher for Unix
An implementation of the
pycommand for Unix-based platforms (with some potential experimentation for good measure 😉)
The goal is to have
pybecome 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
pythoncommand 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
pywhich has existed as the preferred command on Windows for some time.
See the top section of
py --helpfor instructions.
You can either install from crates.io or from source. Both approaches require you install the Rust toolchain. You can use rustup to accomplish this or whatever your OS suggests.
If you want to install from crates.io, run:
cargo install python-launcher
If you want to install from source, run:
cargo install --path .
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_DEBUGset to some value to have it output logging details of how it is performing its search.
py -3.6(specific version)
PATHfor
python3.6
py -3(loose/major version)
PY_PYTHON3environment variable, and if defined and not the empty string then use it as the specific version (e.g.
PY_PYTHON3=3.6)
PATHfor all instances of
python3.*
PATH
py(any version)
${VIRTUAL_ENV}/bin/pythonimmediately if available
.venv/bin/pythonimmediately if available
/usr/bin/python,
/usr/local/bin/python,
/usr/bin/env pythonor
python, proceed based on the version found on that path (bare
pythonis considered the equivalent of not specifying a Python version)
PY_PYTHONenvironment variable, and if defined then use it as the loose or specific version (e.g.
PY_PYTHON=3or
PY_PYTHON=3.6)
PATHfor all instances of
python*.*
PATH