Ask Your Question

How reach octave or Macaulay2 from Sage notebook?

asked 2022-08-29 19:27:29 +0100

murraye gravatar image

updated 2022-08-29 19:37:42 +0100

Enviroment: With SageMath 9-6-1.4.2 (arm64 architecture) under macOS 12.5.1 on an M1 Mac, I cannot directly access either octave or Macaulay2.

  • Octave is in /opt/local/bin and the Macaulay2 executable M2 is in /Applications/Macaulay2-1.20/bin.
  • Both paths were already in the path exported from my .profile (this is relevant to possible workarounds #1, below).
  • I can run both M2 and octave successfully from a Terminal command-line.

Problems: Octave: In the jupyter notebook (with the SageMath 9.6 kernel running, I evaluated:


The long error that ensued included:

RuntimeError: unable to start octave because the command "octave-cli --no-line-editing --silent --eval 'PS2(PS1());more off' --persist" failed: The command was not found or was not executable: octave-cli.

Similarly, when I evaluated

macaulay2('3/5 + 7/11')

I get a long error message that includes:

TypeError: unable to start macaulay2 because the command 'M2 --no-debug --no-readline --silent -e \'sageLoadMode = false;ZZ#{Standard,Core#"private dictionary"#"InputPrompt"} = ZZ#{Standard,Core#"private dictionary"#"InputContinuationPrompt"} = lineno -> if(sageLoadMode) then "_EGAS_LOAD_ : " else "_EGAS_ : ";printWidth = 0;lineNumber = 10^9;sageAssign = (k, v) -> (if not instance(v, Sequence) then use v; k <- v);\'' failed: The command was not found or was not executable: M2.

Possible workarounds:

  1. The method described in This does not work for me, as it now causes not to open at all. (Since the current executable inside the package is named SageMath rather than Sage,I did changeSagetoSageMathfor the name of the added shell script, in the last line of that shell script, and as the value ofCFBundleExecutableininfo.plist`).
  2. The method described in the first comment at

For Macaulay2, this sort of thing does work:


For Octave:


This does not work! Error:

TypeError Traceback (most recent call last)
/var/folders/r2/v_ly_rjj6_v1qpzx4kqy_mqr0000gn/T/ipykernel_4852/ in <module>
----> 1 oc=octave(command='/opt/local/bin/octave')

TypeError: Interface.__call__() got an unexpected keyword argument 'command'


(a) the workaround 2 for the call to Macaulay2 seems awkward. How can one take care of the path issue transparently?

(b) how make the call to octave work, too?

edit retag flag offensive close merge delete


You could try Octave(command=/opt/local/bin/octave-cli) (capital O). You could also try setting the environment variable SAGE_OCTAVE_COMMAND to /opt/local/bin/octave or maybe even better, /opt/local/bin/octave-cli (if that exists). What does os.environ['PATH'] return?

John Palmieri gravatar imageJohn Palmieri ( 2022-08-29 23:04:40 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-08-29 23:20:34 +0100

updated 2022-08-29 23:24:58 +0100

Based on my brief experiments, I think it is a PATH issue. Within a single notebook, you should be able to do

os.environ['PATH'] += ':/opt/local/bin:/Applications/Macaulay2-1.20/bin/'

and then Sage should be able to find the relevant executables. If this works, then you can create a file $HOME/.sage/init.sage containing that command. The commands in init.sage are executed every time you run Sage, so this will automatically modify your PATH every time you run Sage.

(In a little more detail, I think that the Mac binaries intentionally use a limited value for the PATH variable: they do not just read it from your environment. So you need to modify PATH yourself if you want something beyond the default for the Sage Mac app.)

See also for another way to permanently customize your PATH.

edit flag offensive delete link more


I thought that appending those two directories to /etc/paths would accomplish the same thing, but that does not work.

murraye gravatar imagemurraye ( 2022-08-30 02:57:03 +0100 )edit

Right, anything coming from the environment is likely to be ignored by the Sage app. This is specific to the pre-built app: people who instead compile Sage themselves end up with a version that sees the user's ordinary environment.

John Palmieri gravatar imageJohn Palmieri ( 2022-08-30 03:38:17 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-08-29 19:27:29 +0100

Seen: 154 times

Last updated: Aug 29 '22