Ask Your Question

Running octave from the sage notebook

asked 2011-02-16 14:40:16 +0200

Rick gravatar image

I'm trying to run octave through the sage notebook. When I try to evaluate a cell (e.g. x = linspace(0,1,100)), I get the error message:

RuntimeError: Unable to start octave

Examining the traceback in more detail doesn't point to anything that suggests how to fix the problem, and I was wondering whether anyone else had this problem. Octave is installed on my computer, and runs fine from the command line. Can anyone help me with this? Thanks in advance!

edit retag flag offensive close merge delete


That is cool, the syntax in OCTAVE is almost identical to MATLAB.. PS, can we use YALMIP under SAGE?

gundamlh gravatar imagegundamlh ( 2013-11-15 07:31:01 +0200 )edit

5 Answers

Sort by ยป oldest newest most voted

answered 2011-02-16 15:10:53 +0200

kcrisman gravatar image

Have you let Sage know where Octave is? That is, is Octave in your PATH? What I mean is whether you can just type octave to launch octave, or if you have to do something like /path/to/octave/octave_executable (the latter might not be visible to Sage). Otherwise I'm out of ideas, too.

edit flag offensive delete link more


I believe so. My .bashrc file extends the path to include /opt/local/bin/, which is where MacPorts installs octave. However, I don't know whether *sage* can find octave. Maybe I'll try to make a soft link to /usr/local/bin/ or /usr/bin/ or something.

Rick gravatar imageRick ( 2011-02-16 16:21:50 +0200 )edit

Solved. See the answer below.

Rick gravatar imageRick ( 2011-02-16 16:24:00 +0200 )edit

Great. Yeah, I'm not exactly sure what path Sage searches as opposed to one's standard path. Glad you could solve it!

kcrisman gravatar imagekcrisman ( 2011-02-16 21:07:20 +0200 )edit

answered 2013-03-14 07:41:36 +0200

Emmanuel Briand gravatar image

updated 2013-03-14 07:43:43 +0200

I solved the same problem as follows: in the notebook I ran the SAGE command

os.environ["PATH"]+=": ... path to the binary for octave"

For instance


on my Mac with This gives SAGE the information it needs to find octave.

Instead of writing this in the sage notebook every time you want to use octave, you may write it in your .sage/init.sage file.

edit flag offensive delete link more

answered 2013-04-20 20:02:56 +0200

droppit gravatar image

Similar to above, the following worked for me from the notebook interface of sage:


Octave was installed on my system using MacPorts.

I found that octave.eval('2+2') worked immediately in the notebook, but octave(2+2), required:

octave = Octave()

otherwise it errored with "ValueError: The octave session in which this object was defined is no longer running."

Note: octave.eval returns a string, usually with "ans =", whereas octave() returns a number that I could perform further operations on.

You may want to put octave.quit(True) at the end. I don't understand what is actually going on well, so take my advice with caution.

see also:

edit flag offensive delete link more

answered 2015-07-22 15:56:18 +0200

quantum7 gravatar image

Although the question doesn't explicitly say so, I'm going to guess that the OP is running OSX (as assumed in other answers).

The fundamental problem here is that OSX applications don't read .bashrc or .profile like the shell does. There are several ways to modify the PATH variable for Mac Applications, as described on this stack exchange question. I used the wrapper-script answer by Rene to set my environment for Sage. It has the advantage of providing the same environment to that you would expect at the command line, and it works across all notebooks (unlike above answers that modify PATH from within the notebook).

  1. Create a file at /Applications/ with the following text:

    if [[ -x $HOME/.profile ]]; then
      source $HOME/.profile
    exec "`dirname \"$0\"`/Sage" "$@"
  2. Make the file executable

    chmod +x /Applications/Sage-*.app/Contents/MacOS/
  3. Edit /Applications/ Change the CFBundleExecutable to point to the wrapper script

  4. Notify LaunchServices that the Info.plist has changed, either by restarting or by running

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/Sage-*.app

This solution will also address errors running other cell interpreters, such as the LaTeX 'PDFLaTeX does not seem to be installed' error.

edit flag offensive delete link more


In current Sage-9-6 for macOS, the executable in /Applications/ is SageMath. So in Step 1, should /Sage not be instead /SageMath? (And then it would be reasonable to name the shell file and use that in Step 3.) Also, in Step 4, it seems necessary to replace Sage-* with SageMath-*.

murraye gravatar imagemurraye ( 2022-08-29 17:44:02 +0200 )edit

In fact, this method does not seem to work at all: Now when I open from /Applications, nothing whatsoever seems to happen! I no longer get the little pop-up menu asking whether to launch a command-line session or a jupyter session.

murraye gravatar imagemurraye ( 2022-08-29 18:57:51 +0200 )edit

answered 2011-02-16 16:25:04 +0200

Rick gravatar image

As per kcrisman's answer above, I added a softlink from /opt/local/bin/octave to /usr/bin/octave, and now the sage server works. Similarly adding a link to /usr/local/bin/octave did not work.

edit flag offensive delete link more


You don't have /usr/local/bin in your `PATH` - this is why the second one didn't work.

ppurka gravatar imageppurka ( 2013-03-14 12:31:44 +0200 )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


Asked: 2011-02-16 14:40:16 +0200

Seen: 2,821 times

Last updated: Jul 22 '15