@@ -4,7 +4,8 @@ Version: $Revision$
4
4
Last-Modified: $Date$
5
5
Author: Kerrick Staley <
[email protected] >,
6
6
7
-
7
+
8
+
8
9
Status: Active
9
10
Type: Informational
10
11
Content-Type: text/x-rst
@@ -22,8 +23,9 @@ Python interpreter (i.e. the version invoked by the ``python`` command).
22
23
23
24
* ``python2`` will refer to some version of Python 2.x.
24
25
* ``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.
27
29
* however, end users should be aware that ``python`` refers to ``python3``
28
30
on at least Arch Linux (that change is what prompted the creation of this
29
31
PEP), so ``python`` should be used in the shebang line only for scripts
@@ -43,8 +45,7 @@ Recommendation
43
45
* When invoked, ``python2`` should run some version of the Python 2
44
46
interpreter, and ``python3`` should run some version of the Python 3
45
47
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
48
49
Python as the ``python2`` command (however, note that some distributions
49
50
have already chosen to have ``python`` implement the ``python3``
50
51
command; see the `Rationale`_ and `Migration Notes`_ below).
@@ -62,14 +63,30 @@ Recommendation
62
63
context.
63
64
* One exception to this is scripts that are deliberately written to be source
64
65
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.
66
71
* When reinvoking the interpreter from a Python script, querying
67
72
``sys.executable`` to avoid hardcoded assumptions regarding the
68
73
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.
69
86
70
87
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]_) .
73
90
74
91
75
92
Rationale
@@ -91,11 +108,6 @@ on the part of distribution maintainers.
91
108
Future Changes to this Recommendation
92
109
=====================================
93
110
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
-
99
111
This recommendation will be periodically reviewed over the next few years,
100
112
and updated when the core development team judges it appropriate. As a
101
113
point of reference, regular maintenance releases for the Python 2.7 series
@@ -150,15 +162,13 @@ making such a change.
150
162
* When the ``pythonX.X`` binaries are provided by a distribution, the
151
163
``python2`` and ``python3`` commands should refer to one of those files
152
164
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
155
167
operate on other distributions. This will reduce problems if the
156
168
distribution later decides to change the version of the Python interpreter
157
169
that the ``python`` command invokes, or if a sysadmin installs a custom
158
170
``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.
162
172
* If the above point is adhered to and sysadmins are permitted to change the
163
173
``python`` command, then the ``python`` command should always be implemented
164
174
as a link to the interpreter binary (or a link to a link) and not vice
@@ -267,6 +277,10 @@ References
267
277
.. [6] PEP 394 - Clarification of what "python" command should invoke
268
278
(https://mail.python.org/pipermail/python-dev/2014-September/136374.html)
269
279
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
+
270
284
Copyright
271
285
===========
272
286
This document has been placed in the public domain.
0 commit comments