# Running octave from the sage notebook

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 close merge delete

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

( 2013-11-15 00:31:01 -0500 )edit

Sort by » oldest newest most voted

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.

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.

( 2011-02-16 09:21:50 -0500 )edit

( 2011-02-16 09:24:00 -0500 )edit

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

( 2011-02-16 14:07:20 -0500 )edit

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

os.environ["PATH"]+=":/Applications/Octave.app/Contents/Resources/bin"


on my Mac with Octave.app. 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.

more

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 Sage.app 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/Sage-version.app/Contents/MacOS/Sage.sh with the following text:

#!/bin/bash
if [[ -x $HOME/.profile ]]; then source$HOME/.profile
fi
exec "dirname \"$0\"/Sage" "$@"

2. Make the file executable

chmod +x /Applications/Sage-*.app/Contents/MacOS/Sage.sh

3. Edit /Applications/Sage-version.app/Contents/Info.plist. Change the CFBundleExecutable to point to the wrapper script

<key>CFBundleExecutable</key>
<string>Sage.sh</string>

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.

more

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

os.environ["PATH"]+=":/opt/local/bin"


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()
octave._start()


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.

more

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.

more

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

( 2013-03-14 06:31:44 -0500 )edit