GSoC 2021: How to setup the Octave kernel for Jupyter

Hello there. In this blog post, I will describe how to install and configure the Octave kernel for Jupyter. Let’s get started.

To install the kernel, run pip install octave_kernel. If the kernel is still not detected run python -m octave_kernel install --user but note that the last command works only for the current user.

To configure the kernel I did the following:

1- Configure your environment to have the octave-cli executable:

This can be done by either adding the directory of that executable to your PATH or by exporting the directory as an environment variable called OCTAVE_EXECUTABLE.

Note that octave-cli executable can be found in the same directory that contains your octave executable

2- Verify your configuration:

run python -m octave_kernel.check to check if everything is fine and to check available graphics toolkits. The output should look like this:

Connecting to Octave...
Octave connection established
Octave Kernel vx.x.x running GNU Octave vx.x.x
Graphics toolkit: fltk
Available toolkits: 
  [1,1] = fltk
  [1,2] = gnuplot

3- (Optional) Have more beautiful plots:

Right now, the plots may look like this:

This is because the Octave kernel uses the octave-cli executable to run the kernel. the octave-cli executable doesn’t support qt which enables you to have more beautiful plots. There is two way to do this.

  • Make a symbolic link to the octave executable:
    • Create the symbolic link by running: ln -s path_to_octave_binary /usr/bin/octave-cli-jupyter
    • Export the symbolic link by running export OCTAVE_EXECUTABLE=octave-cli-jupyter
    • Create a new file $HOME/.jupyter/ and paste c.OctaveKernel.inline_toolkit = "qt" to it.
  • Use gnuplot-qt:
    • You can have more beautiful plots if you use gnuplot-qt. To do this, install gnuplot-qt using your package manager and add setenv("GNUTERM", "qt") and graphics_toolkit("gnuplot") to your .octaverc file.

Note: Some times, the more beautiful plots don’t appear for some formats on some systems. You can specify a different format using the %plot -f <backend> magic. Magic commands are IPython commands provided by the IPython kernel. They are not Octave commands.

For example: if it didn’t appear using png format, try using the svg format.

This is the same plot now after configuration:

You can also know how to build and publish Octave JupyterLab Docker/Singularity images in this blog post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: