Ask Your Question
2

Running octave from the sage notebook

asked 2011-02-16 07:40:16 -0500

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

Comments

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 00:31:01 -0500 )edit

5 answers

Sort by ยป oldest newest most voted
3

answered 2011-02-16 08:10:53 -0500

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

Comments

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 09:21:50 -0500 )edit

Solved. See the answer below.

Rick gravatar imageRick ( 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!

kcrisman gravatar imagekcrisman ( 2011-02-16 14:07:20 -0500 )edit
5

answered 2013-03-14 01:41:36 -0500

Emmanuel Briand gravatar image

updated 2013-03-14 01:43:43 -0500

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.

edit flag offensive delete link more
2

answered 2015-07-22 08:56:18 -0500

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 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.

edit flag offensive delete link more
1

answered 2013-04-20 13:02:56 -0500

droppit gravatar image

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.

see also: http://www.sagemath.org/doc/reference/interfaces/sage/interfaces/octave.html

edit flag offensive delete link more
1

answered 2011-02-16 09:25:04 -0500

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

Comments

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 06:31:44 -0500 )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

Stats

Asked: 2011-02-16 07:40:16 -0500

Seen: 1,779 times

Last updated: Jul 22 '15