Compatibility shim for /usr/bin/python

Nick Coghlan ncoghlan at gmail.com
Wed Jul 15 07:45:15 UTC 2015


One of the open questions with the Python 3 migration is the eventual
fate of /usr/bin/python.

In response to a question from Robert Kuska, Barry Warsaw recently
pointed me towards Geoffrey Thomas's design proposal for Debian:
https://ldpreload.com/blog/usr-bin-python-23

The gist of the idea is to make /usr/bin/python a custom launcher
rather than a symlink to a specific Python interpreter, and then have
a simple "magic comment" syntax to specify version compatibility.

(These would only apply for a "python" shebang line - "python2" and
"python3" would still be symlinks to a specific interpreter)

Python 2 only (fail if Python 2 not installed):
    No comment
    # pyversion: 2.x+

Python 3 only (fail if Python 3 not installed):
    # pyversion: 3.x+

Python 2 & 3 compatible:
    # pyversion: 2.x+, 3.x+

In all cases, the ".x" would be a *specific* Python version.

Thomas has a very simple proof of concept implementation at
https://github.com/geofft/pythonmux/blob/master/pythonmux.c that just
uses "/usr/bin/pythonX.Y" as its registration mechanism for making the
launcher aware of additional runtimes.

It seems to me that this would be an excellent starting point for
preserving "/usr/bin/python" compatibility for end user scripts.

Providing such a runtime multiplexer would also potentially provide a
way to introduce per-user configuration of the "default Python", such
that a user could run their *own* scripts in a different Python
interpreter by default (e.g. an SCL, or PyPy), without having to touch
the default Python at the system level (i.e. when running Python
scripts as root).

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the python-devel mailing list