From d5760f252d7c43998be1e6f16e938a45bad3e504 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 29 Sep 2024 23:29:54 +0200 Subject: [PATCH] Try "python" before "python3" in python-mode Prefer whatever version of Python that "python" might point to; use "python3" if it doesn't exist. On recent versions of typical GNU/Linux distributions, "python" either does not exist or it points to Python 3. In (presumed rare) cases where "python" points to Python 2 instead, users are now expected to manually customize these variables if they want to use Python 3. * lisp/progmodes/python.el (python-interpreter) (python-shell-interpreter): Prefer "python" to "python3". Ref: https://lists.gnu.org/r/emacs-devel/2024-09/msg00885.html (cherry picked from commit dd4c67907eb3084c6f55828c51bca1675a98376d) --- etc/NEWS | 11 +++++++++++ lisp/progmodes/python.el | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 756598afe6c..417f0c6a08b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -403,6 +403,17 @@ toggle. Putting (require 'midnight) in your init file no longer activates the mode. Now, one needs to say (midnight-mode +1) instead. +** Python mode + +--- +*** Prefer "python" for 'python-interpreter' and 'python-shell-interpreter'. +On recent versions of mainstream GNU/Linux distributions, "python" +either does not exist or it points to Python 3. These user options now +default to using "python", falling back to "python3" if it does not +exist. If "python" points to Python 2 on your system, you now have to +customize these variables to "python3" if you want to use Python 3 +instead. + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 0399c328ff5..6e7a398aee7 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -313,8 +313,8 @@ :link '(emacs-commentary-link "python")) (defcustom python-interpreter - (cond ((executable-find "python3") "python3") - ((executable-find "python") "python") + (cond ((executable-find "python") "python") + ((executable-find "python3") "python3") (t "python3")) "Python interpreter for noninteractive use. Some Python interpreters also require changes to @@ -2739,8 +2739,8 @@ position, else returns nil." :safe 'stringp) (defcustom python-shell-interpreter - (cond ((executable-find "python3") "python3") - ((executable-find "python") "python") + (cond ((executable-find "python") "python") + ((executable-find "python3") "python3") (t "python3")) "Python interpreter for interactive use. @@ -2748,7 +2748,7 @@ Some Python interpreters also require changes to `python-shell-interpreter-args'. In particular, setting `python-shell-interpreter' to \"ipython3\" requires setting `python-shell-interpreter-args' to \"--simple-prompt\"." - :version "28.1" + :version "31.1" :type 'string) (defcustom python-shell-internal-buffer-name "Python Internal" -- 2.39.2