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.
py -3.6
(specific version)PATH
for python3.6
py -3
(loose/major version)PY_PYTHON3
environment variable if defined
and not the empty string (e.g. PY_PYTHON3=3.6
)PATH
for all instances of python3.Y
Y
that earliest on PATH
py
(any/unknown version)${VIRTUAL_ENV}/bin/python
immediately if available/usr/bin/python
, /usr/local/bin/python
,
/usr/bin/env python
or python
, proceed based on the version found
(bare python
is considered the equivalent of not specifying a
Python version)PY_PYTHON
environment variable if defined
(e.g. PY_PYTHON=3
or PY_PYTHON=3.6
)PATH
for all instances of pythonX.Y
X.Y
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.)
PEP 397: Python launcher for Windows / PEP 486: Make the Python Launcher aware of virtual environments (documentation; source)
Everything in bold is required to hit MVP.
.venv/pyvenv.cfg
and use that (basically an implicit setting of $VIRTUAL_ENV
)?PATH
PATH
search, but need to make sure)OsString
/OsStr
everywhere (versus now which is wherever it's easy w/ path::Path
)?
CString
)python_launcher
extension module
pylauncher
or pyfinder
to follow Python practices (if it
isn't too much trouble)2.7-framework
for
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
?2.7
for
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
python3.7
like pypy3
?pypy3
to its Python version?.venv/bin/python
(while keeping the python
name)?
VENV_REDIRECT
variant in launcher.c
-h
, --list
, and version specifier support -- in this situation to make this work../pyvenv.cfg
and its home
key to determine where to look for the Python executable
home
has multiple Python executables installed? Might need to add an executable
key to give full path to the creating interpreter..pyd
files)site
module to gain ability to specify virtual environment location (while maintaining the invariant on how to detect virtual environments as outlined in the venv
module docs)--json
flag for JSONified --list
output?
--list
somehow denote an activated virtual environment?
nix
for a straight
libc
dependency (to potentially make Debian
packaging easier)
nix
to the latest versionOutput from py --list
on Windows:
Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows
-3.8-64 *
-3.7-64
-3.6-64
-2.7-64
-2.7-64