[-- Attachment #1: Type: text/plain, Size: 380 bytes --] Hi, Python 2 reached EOL about a year ago thus the 'python' command may be missing on some systems. 'python3' is the standard way of invoking the Python 3 interpreter, thus Emacs would have a better chance trying that. The attached patch is already carried in Ubuntu. Cheers, Balint [1] https://www.python.org/doc/sunset-python-2/ -- Balint Reczey Ubuntu & Debian Developer [-- Attachment #2: python3-as-default.patch --] [-- Type: text/x-patch, Size: 799 bytes --] Description: Run python3 command as default instead of python Author: Balint Reczey <balint.reczey@canonical.com> Origin: vendor Forwarded: no Last-Update: 2020-03-25 --- a/lisp/ldefs-boot.el +++ b/lisp/ldefs-boot.el @@ -26539,7 +26539,7 @@ (add-to-list 'interpreter-mode-alist (cons (purecopy "python[0-9.]*") 'python-mode)) -(autoload 'run-python "python" "\ +(autoload 'run-python "python3" "\ Run an inferior Python process. Argument CMD defaults to `python-shell-calculate-command' return --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1952,7 +1952,7 @@ :group 'python :safe 'stringp) -(defcustom python-shell-interpreter "python" +(defcustom python-shell-interpreter "python3" "Default Python interpreter for shell." :type 'string :group 'python)
Balint Reczey wrote: > Python 2 reached EOL about a year ago thus the 'python' command may be > missing on some systems. 'python3' is the standard way of invoking the > Python 3 interpreter, thus Emacs would have a better chance trying > that. > > The attached patch is already carried in Ubuntu. Thanks for the report. > --- a/lisp/ldefs-boot.el > +++ b/lisp/ldefs-boot.el > @@ -26539,7 +26539,7 @@ > > (add-to-list 'interpreter-mode-alist (cons (purecopy "python[0-9.]*") 'python-mode)) > > -(autoload 'run-python "python" "\ > +(autoload 'run-python "python3" "\ This bit is wrong. Firstly, ldefs-boot is a generated file, and secondly, unless Ubuntu is distributing a python3.el, it would just break the autoload. > --- a/lisp/progmodes/python.el > +++ b/lisp/progmodes/python.el > @@ -1952,7 +1952,7 @@ > :group 'python > :safe 'stringp) > > -(defcustom python-shell-interpreter "python" > +(defcustom python-shell-interpreter "python3" (if (executable-find "python3") "python3" "python") is probably how Emacs would normally handle this kind of thing. Or if defaulting to python3 is better (I guess it is): (cond ((executable-find "python3") "python3") ((executable-find "python") "python") (t "python3"))
Hi Glenn,
Thanks for the quick response.
On Wed, Jan 6, 2021 at 5:59 PM Glenn Morris <rgm@gnu.org> wrote:
>
> Balint Reczey wrote:
>
> > Python 2 reached EOL about a year ago thus the 'python' command may be
> > missing on some systems. 'python3' is the standard way of invoking the
> > Python 3 interpreter, thus Emacs would have a better chance trying
> > that.
> >
> > The attached patch is already carried in Ubuntu.
>
> Thanks for the report.
>
> > --- a/lisp/ldefs-boot.el
> > +++ b/lisp/ldefs-boot.el
> > @@ -26539,7 +26539,7 @@
> >
> > (add-to-list 'interpreter-mode-alist (cons (purecopy "python[0-9.]*") 'python-mode))
> >
> > -(autoload 'run-python "python" "\
> > +(autoload 'run-python "python3" "\
>
> This bit is wrong. Firstly, ldefs-boot is a generated file, and
> secondly, unless Ubuntu is distributing a python3.el, it would just
> break the autoload.
>
> > --- a/lisp/progmodes/python.el
> > +++ b/lisp/progmodes/python.el
> > @@ -1952,7 +1952,7 @@
> > :group 'python
> > :safe 'stringp)
> >
> > -(defcustom python-shell-interpreter "python"
> > +(defcustom python-shell-interpreter "python3"
>
> (if (executable-find "python3") "python3" "python")
>
> is probably how Emacs would normally handle this kind of thing.
> Or if defaulting to python3 is better (I guess it is):
>
> (cond ((executable-find "python3") "python3")
> ((executable-find "python") "python")
> (t "python3"))
Indeed, that would be better for very old systems.
Could you please land the proper fix or you would like me to rework mine?
Thanks,
Balint
--
Balint Reczey
Ubuntu & Debian Developer
Balint Reczey <balint.reczey@canonical.com> writes: > Indeed, that would be better for very old systems. > Could you please land the proper fix or you would like me to rework mine? I've now installed Glenn's suggested change in Emacs 28. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no
> Python 2 reached EOL about a year ago thus the 'python' command may be
> missing on some systems.
> 'python3' is the standard way of invoking the Python 3 interpreter,
> thus Emacs would have a better chance trying that.
At least here on Debian, `python` redirects to `python3` or `python2`
depending on some user choice (by installing either `python-is-python3`
or `python-in-python2`).
So I think it makes a lot of sense to keep using `python` rather than
`python3`.
Stefan
Hi Stefan, On Sun, Jan 10, 2021 at 6:42 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote: > > > Python 2 reached EOL about a year ago thus the 'python' command may be > > missing on some systems. > > 'python3' is the standard way of invoking the Python 3 interpreter, > > thus Emacs would have a better chance trying that. > > At least here on Debian, `python` redirects to `python3` or `python2` > depending on some user choice (by installing either `python-is-python3` > or `python-in-python2`). > > So I think it makes a lot of sense to keep using `python` rather than > `python3`. I don't think keeping `python` is a good idea, this would make Emacs considered to be buggy in Debian. Please see https://wiki.debian.org/Python : ... NOTE: Debian testing (bullseye) has removed the "python" package and the '/usr/bin/python' symlink due to the deprecation of Python 2. No packaged scripts should depend on the existence of '/usr/bin/python': if they do, that is a bug that should be reported to Debian. You can use the 'python-is-python3' or 'python-is-python2' packages to restore an appropriate '/usr/bin/python' symlink for third-party or legacy scripts. ... Cheers, Balint -- Balint Reczey Ubuntu & Debian Developer
> I don't think keeping `python` is a good idea, this would make Emacs
> considered to be buggy in Debian.
>
> Please see https://wiki.debian.org/Python :
> ...
> NOTE: Debian testing (bullseye) has removed the "python" package and
> the '/usr/bin/python' symlink due to the deprecation of Python 2. No
> packaged scripts should depend on the existence of '/usr/bin/python':
> if they do, that is a bug that should be reported to Debian. You can
> use the 'python-is-python3' or 'python-is-python2' packages to restore
> an appropriate '/usr/bin/python' symlink for third-party or legacy
> scripts.
> ...
That's a very different situation, tho: what you describe is for Debian
packages, where clearly each package is written&tested to work against
a particular version (or range of versions) of Python.
In contrast the question at hand is "which version of Python should one
start when the user wants to run a Python subprocess". I think it's
reasonable to consider that *if* there is a `python` executable in
$PATH, it makes sense to considered it as the preferred version
of Python.
Stefan
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> In contrast the question at hand is "which version of Python should one
> start when the user wants to run a Python subprocess". I think it's
> reasonable to consider that *if* there is a `python` executable in
> $PATH, it makes sense to considered it as the preferred version
> of Python.
We need to consider multiple scenarios:
1. Both, ‘python’ as well as ‘python3’ executables, are in PATH.
1.1 ‘python’ pointing to Python v2
1.2 ‘python’ pointing to Python v3
2. Only ‘python’ is in PATH
- This is surely Python v2 otherwise ‘python3’ will also be in PATH
3. Only ‘python3’ is in PATH
In (2) and (3), we have only one choice to pick. The point of discussion
are (1.1) and (1.2).
In (1.2), user has somehow customized the system PATH and made Python v3
as default. So we can obey what the user wants - pick
‘python’. Although, I don’t know if there is a standard prescription on
‘python2’ executable, but on some systems this is available (macOS). In
case of (1.2), we can simply pick ‘python’.
(1.1) is the case where both Python v2 and Python v3 are installed and
we don’t know what the user wants. ‘python’ and ‘python3’ (and may be
‘python2’) are in PATH.
In (1.1), my opinion is that we should pick the version which is
officially supported by the Python Community - pick ‘python3’.