# HG changeset patch # User Rik # Date 1657387377 25200 # Node ID 6cfc7af8eacc6310cfd38f767ec8c472dc6b501a # Parent 0c637fa9529ac1a5090c49d60562aafb171799f9 python.m: Add code to find python executable on different platforms (bug #62733) * python.m: New persistent variable "pyexec" to hold name of python executable. * python.m (get_python_executable): New function to find name of python executable. diff -r 0c637fa9529a -r 6cfc7af8eacc scripts/miscellaneous/python.m --- a/scripts/miscellaneous/python.m Sat Jul 09 09:58:02 2022 -0700 +++ b/scripts/miscellaneous/python.m Sat Jul 09 10:22:57 2022 -0700 @@ -38,6 +38,8 @@ function [output, status] = python (scriptfile = "-c ''", varargin) + persistent pyexec = get_python_executable (); + if (ischar (scriptfile) && ( (nargin == 1 && ! isempty (scriptfile)) || (nargin != 1 && iscellstr (varargin)))) @@ -46,7 +48,7 @@ scriptfile = file_in_loadpath (scriptfile); endif - [status, output] = system (["python ", scriptfile, ... + [status, output] = system ([pyexec " " scriptfile, ... sprintf(" %s", varargin{:})]); else error ("python: invalid arguments"); @@ -54,5 +56,20 @@ endfunction +function pyexec = get_python_executable () + + pyexec = getenv ("PYTHON"); + if (isempty (pyexec)) + ## PEP394 says Python 3 installs should all provide this command + pyexec = "python3"; + + if (ispc () && (! isunix ())) + ## 2020-03: Python.org installer/Anaconda do not provide python3 + pyexec = "python"; + endif + endif + +endfunction + %!error python (123)