Need help with python-launcher?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

brettcannon
142 Stars 6 Forks MIT License 376 Commits 9 Opened issues

Description

Python launcher for Unix

Services available

!
?

Need anything else?

Contributors list

# 5,534
Visual ...
Common ...
jupyter
python-...
350 commits
# 48,236
awk
slack
gRPC
query-l...
1 commit
# 6,983
Python
cookiec...
pytest
Heroku
1 commit

The Python Launcher for Unix

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.

Installation

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 .

Search order

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.

py -3.6
(specific version)

  1. Search
    PATH
    for
    python3.6

py -3
(loose/major version)

  1. Check for the
    PY_PYTHON3
    environment variable, and if defined and not the empty string then use it as the specific version (e.g.
    PY_PYTHON3=3.6
    )
  2. Search
    PATH
    for all instances of
    python3.*
  3. Find the executable with the newest version number that comes earliest on
    PATH

py
(any version)

  1. Use
    ${VIRTUAL_ENV}/bin/python
    immediately if available
  2. Use
    .venv/bin/python
    immediately if available
  3. If the first argument is a file path ...
    1. Check for a shebang
    2. If shebang path starts with
      /usr/bin/python
      ,
      /usr/local/bin/python
      ,
      /usr/bin/env python
      or
      python
      , proceed based on the version found on that path (bare
      python
      is considered the equivalent of not specifying a Python version)
  4. Check for the
    PY_PYTHON
    environment variable, and if defined then use it as the loose or specific version (e.g.
    PY_PYTHON=3
    or
    PY_PYTHON=3.6
    )
  5. Search
    PATH
    for all instances of
    python*.*
  6. Find the executable with the newest version that is earliest on
    PATH

TODO

Issues to finish to reach MVP

Appendix

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.