Skip to content

Commit cd59ec0

Browse files
authored
PEP 394: Allow the python command to not be installed, and other minor edits (GH-630)
* Allow the `python` command to not be installed, and other minor edits - Distributions can omit the ``python`` command even when ``python2`` is installed in test environments, build systems, and other controlled environments where being explicit is valued more than user experience. - Users, by a deliberate action, change ``python`` to invoke Python 3. Activating a venv counts as such an action. - Other edits and clarifications * Add myself as an author
1 parent 4d98276 commit cd59ec0

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

pep-0394.txt

+32-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Version: $Revision$
44
Last-Modified: $Date$
55
Author: Kerrick Staley <[email protected]>,
66
Nick Coghlan <[email protected]>,
7-
Barry Warsaw <[email protected]>
7+
Barry Warsaw <[email protected]>,
8+
Petr Viktorin <[email protected]>
89
Status: Active
910
Type: Informational
1011
Content-Type: text/x-rst
@@ -22,8 +23,9 @@ Python interpreter (i.e. the version invoked by the ``python`` command).
2223

2324
* ``python2`` will refer to some version of Python 2.x.
2425
* ``python3`` will refer to some version of Python 3.x.
25-
* for the time being, all distributions *should* ensure that ``python``
26-
refers to the same target as ``python2``.
26+
* for the time being, all distributions *should* ensure that ``python``,
27+
if installed, refers to the same target as ``python2``, unless the user
28+
deliberately overrides this or a virtual environment is active.
2729
* however, end users should be aware that ``python`` refers to ``python3``
2830
on at least Arch Linux (that change is what prompted the creation of this
2931
PEP), so ``python`` should be used in the shebang line only for scripts
@@ -43,8 +45,7 @@ Recommendation
4345
* When invoked, ``python2`` should run some version of the Python 2
4446
interpreter, and ``python3`` should run some version of the Python 3
4547
interpreter.
46-
* The more general ``python`` command should be installed whenever
47-
any version of Python 2 is installed and should invoke the same version of
48+
* If the ``python`` command is installed, it should invoke the same version of
4849
Python as the ``python2`` command (however, note that some distributions
4950
have already chosen to have ``python`` implement the ``python3``
5051
command; see the `Rationale`_ and `Migration Notes`_ below).
@@ -62,14 +63,30 @@ Recommendation
6263
context.
6364
* One exception to this is scripts that are deliberately written to be source
6465
compatible with both Python 2.x and 3.x. Such scripts may continue to use
65-
``python`` on their shebang line without affecting their portability.
66+
``python`` on their shebang line.
67+
* When packaging software that is source compatible with both versions,
68+
distributions may change such ``python`` shebangs to ``python3``.
69+
This ensures software is used with the latest version of
70+
Python available, and it can remove a dependency on Python 2.
6671
* When reinvoking the interpreter from a Python script, querying
6772
``sys.executable`` to avoid hardcoded assumptions regarding the
6873
interpreter location remains the preferred approach.
74+
* In controlled environments aimed at expert users, where being explicit
75+
is valued over user experience (for example, in test environments and
76+
package build systems), distributions may choose to not provide the
77+
``python`` command even if ``python2`` is available.
78+
(All software in such a controlled environment must use ``python3`` or
79+
``python2`` rather than ``python``, which means scripts that deliberately
80+
use ``python`` need to be modified for such environments.)
81+
* When a virtual environment (created by the PEP 405 ``venv`` package or a
82+
similar tool) is active, the ``python`` command should refer to the
83+
virtual environment's interpreter. In other words, activating a virtual
84+
environment counts as deliberate user action to change the default
85+
``python`` interpreter.
6986

7087
These recommendations are the outcome of the relevant python-dev discussions
71-
in March and July 2011 ([1]_, [2]_), February 2012 ([4]_) and
72-
September 2014 ([6]_).
88+
in March and July 2011 ([1]_, [2]_), February 2012 ([4]_),
89+
September 2014 ([6]_), and discussion on GitHub in April 2018 ([7]_).
7390

7491

7592
Rationale
@@ -91,11 +108,6 @@ on the part of distribution maintainers.
91108
Future Changes to this Recommendation
92109
=====================================
93110

94-
It is anticipated that there will eventually come a time where the third
95-
party ecosystem surrounding Python 3 is sufficiently mature for this
96-
recommendation to be updated to suggest that the ``python`` symlink
97-
refer to ``python3`` rather than ``python2``.
98-
99111
This recommendation will be periodically reviewed over the next few years,
100112
and updated when the core development team judges it appropriate. As a
101113
point of reference, regular maintenance releases for the Python 2.7 series
@@ -150,15 +162,13 @@ making such a change.
150162
* When the ``pythonX.X`` binaries are provided by a distribution, the
151163
``python2`` and ``python3`` commands should refer to one of those files
152164
rather than being provided as a separate binary file.
153-
* It is suggested that even distribution-specific packages follow the
154-
``python2``/``python3`` convention, even in code that is not intended to
165+
* It is strongly encouraged that distribution-specific packages use ``python2``
166+
or ``python3`` rather than ``python``, even in code that is not intended to
155167
operate on other distributions. This will reduce problems if the
156168
distribution later decides to change the version of the Python interpreter
157169
that the ``python`` command invokes, or if a sysadmin installs a custom
158170
``python`` command with a different major version than the distribution
159-
default. Distributions can test whether they are fully following this
160-
convention by changing the ``python`` interpreter on a test box and checking
161-
to see if anything breaks.
171+
default.
162172
* If the above point is adhered to and sysadmins are permitted to change the
163173
``python`` command, then the ``python`` command should always be implemented
164174
as a link to the interpreter binary (or a link to a link) and not vice
@@ -267,6 +277,10 @@ References
267277
.. [6] PEP 394 - Clarification of what "python" command should invoke
268278
(https://mail.python.org/pipermail/python-dev/2014-September/136374.html)
269279

280+
.. [7] PEP 394: Allow the `python` command to not be installed, and other
281+
minor edits
282+
(https://github.com/python/peps/pull/630)
283+
270284
Copyright
271285
===========
272286
This document has been placed in the public domain.

0 commit comments

Comments
 (0)