78d04f1seqlab: write and view pulseq MRI sequences in the browserJeremy Magland 1function [sigPyOK, pythonExe] = isSigPyAvailable()
2%ISSIGPYAVAILABLE Test whether Python is available and has SigPy installed
3% If successfull stores a persistent state after the first call to accelerate
4% subsequent checks; use clear GLOBALS to reset the persistent state.
6persistent static_pythonExe;
8if ~isempty (static_pythonExe)
9 sigPyOK=true;
10 pythonExe=static_pythonExe;
11 return;
12end
14executables = {'python3', 'python', 'py'};
15test_commands = {'which -a', 'where'};
16exes = {};
18if ispc
19 null_out = 'nul';
20 test_commands=test_commands(2:end); % there is no which on Windows anyway...
21else
22 null_out = '/dev/null';
23end
25for c=1:length(test_commands)
26 for e=1:length(executables)
27 cmd=sprintf('%s %s 2>%s',test_commands{c},executables{e},null_out);
28 [status, output] = system(cmd);
29 if status~=0, continue; end
30 lines = regexp(output,'\n','split');
31 for l=1:length(lines)
32 exe=mr.aux.strstrip(lines{l});
33 if isempty(exe), continue; end
34 % test for Python with sigPy
35 cmd=sprintf('"%s" -c "import sigpy" 2>%s',exe,null_out);
36 [status, output] = system(cmd);
37 if status ~= 0, continue; end
38 % found it!
39 sigPyOK=true;
40 pythonExe=exe;
41 static_pythonExe=exe;
42 return;
43 end
44 end
45end
47% did't find python or functional sigPy
48sigPyOK = false;
49pythonExe = '';
51end