[PYTHON] Install octave_kernel on Jupyter [additional]

Preface

To take a certain Online Machine Learning Course, [Octave](http: http: //www.coursera.org/learn/machine-learning "Machine Learning --Stanford University | Coursera") //www.gnu.org/software/octave/ "GNU Octave") has been installed.

So, I searched for the Octave kernel in Jupyter and installed it. I was a little addicted to it, so I recorded it for information sharing.

[2015/07/14 09:00 postscript]

I was checking the operation and was addicted to handling Japanese, so I added and corrected the article.

environment

[^ 4]: The main Python is 2.7.9, and 3.4.3 is co-installed with pyenv and the kernel is added so that both work. For details, refer to the article the other day (Jupyter Preferences Supplement #pythontokai). [^ 1]: IPython was also upgraded, so I updated it. Or rather ... See ↓

Octave installation

Octave seems to be able to download and install the binaries, but I installed it with Homebrew. I was able to install it using the same procedure, almost independent of the OSX version (although it will take some time).

$ brew update
$ brew tap homebrew/science
$ brew install octave

Also, Java was already in my environment, so there was no problem starting it.

$ octave --version
GNU Octave, version 3.8.2
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-apple-darwin13.4.0".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
$ 

Install octave_kernel

1. Package installation

Jupyter's Octave kernel is provided as a Python package (Package Index> octave_kernel), so pip You can install it with the command.

As a caveat, install it on Python3 so that there is no problem in handling Japanese. </ ins> (details below)

$ pyenv shell 3.4.3
$ pip install pip --upgrade
$ pip install octave_kernel

Multiple packages will be installed, including dependencies. By the way, if you do pip install octave_kernel --upgrade, it seems that it will be upgraded when the dependent packages can be updated [^ 3].

[^ 3]: Actually, IPython has now increased from 3.1.0 to 3.2.0 and is now "Wow" (^-^;

Installation confirmation [^ 5]:

ls  ~/.pyenv/versions/3.4.3/lib/python3.4/site-packages/ | grep octave_kernel
octave_kernel-0.11.0-py3.4.egg

[^ 5]: When I installed it on Python2.7, I could see it with ʻimp.find_module ('octave_kernel')`, but with Python3.4 I couldn't see it (I was told I couldn't find it, (Mystery), so I'm just checking if the file exists.

2. Kernel settings

This step is ** essentially unnecessary **. If the installation is successful, the kernel settings should be done [^ 2]. First, try [3. Operation check](# 3-% E5% 8B% 95% E4% BD% 9C% E7% A2% BA% E8% AA% 8D) in the next section and say "Kernel not found" If you get an error to that effect, perform the following manual kernel settings.

[^ 2]: When the kernel settings are done automatically, it seems that the config file is generated in / usr / local / share / jupyter / kernels / instead of in ~ / .ipython / kernels. The previously installed bash_kernel settings are there.

Even if you say manual setting of the kernel, all you have to do is create the kernel.json file yourself and place it in an appropriate location.

$ cd ~/.ipython/kernels
$ mkdir -p octave_kernel && cd octave_kernel
$ vi kernel.json

kernel.json (sample):

kernel.json


{
    "argv": [
        "/path/to/user_home/.pyenv/versions/3.4.3/bin/python",
        "-m", "octave_kernel",
        "-f", "{connection_file}"
    ],
    "display_name": "Octave",
    "language": "octave",
    "name": "octave_kernel"
}

3. Operation check

If you get an error saying "Kernel not found", see the previous section [2. Kernel settings](# 2-% E3% 82% AB% E3% 83% BC% E3% 83% 8D% E3% 83% AB. Go back to% E3% 81% AE% E8% A8% AD% E5% AE% 9A) and manually (re) configure the kernel.

$ ipython console --kernel=octave_kernel
IPython Console 3.2.0

In [1]: printf("Hello, World!\n")
gnuplot 5.0 patchlevel 0
Out[1]:
Hello, World!


In [2]: #Ctrl to exit+D
Do you really want to exit ([y]/n)?

What if gnuplot works when I just tried printf? It feels like (^-^;

Check with Jupyter

The kernel has been added properly:

kernels_20150704.png

Easy display confirmation:

IOctave_1st.png

By the way, the graph is drawn in SVG. Moreover, the size is automatically adjusted according to the width of the cell. If you change the width of the browser, it will be resized in real time. Somehow fun w

Display with nbviewer

[Addition: 2015/07/14] Notes

Even with Python2.7.x, octave_kernel can be installed successfully, but there was a problem that Japanese (or Unicode character string) was not handled properly and an internal error occurred when displaying. I did some research, but octave_kernel.py or its source (defining MetaKernel, which is a super class of ʻOctaveKernel`) [MetaKernel](https://pypi.python.org/ pypi / metakernel "metakernel 0.9.0: Python Package Index") It seems to be a problem on the side [^ 6], so I stopped chasing deeply.

Instead, isn't it okay if String is Python3 integrated with Unicode string? When I tried it, it worked as expected without any problems. It was good to coexist with the environment (^-^)

So, to use OctaveKernel (and other kernels that use MetaKernel), use Python3.

As a result, I installed octave_kernel once with 2.7.x and then installed it again with 3.x, but the kernel was successfully installed under (/ usr / local / share / jupyter / kernels). The kernel settings have been overwritten normally (if the environment is set). no problem. If you set it manually, you need to modify the path accordingly.

[^ 6]: Maybe it's a problem that can be solved just by putting a magic comment (# coding: utf-8) at the beginning of the source ...

reference

Recommended Posts

Install octave_kernel on Jupyter [additional]
Golang on jupyter
Jupyter on AWS
Hello X3DOM on Jupyter
Install mecab on Marvericks
Install Tensorflow on Mac
Install TensorFlow on Ubuntu
Install python on WSL
Install Faiss on CentOS 7
Install pyenv on mac
Install pip on Mavericks
Install Python on Pidora.
Install mongodb on termux
Install Scrapy on python3
Install docker on Fedora31
Install numba on CentOS 7.2
Install Ansible on Mac
Install Python on Mac
Install Python 3 on Mac
Install Plone (4.3.6) on MacOSX (10.10.3)
Install PySide2 on Ubuntu
Install Python3.4 on CentOS 6.6
Install Python Jupyter lab
Install gensim on Marvericks
Install JModelica on Ubuntu
Install Anaconda on Windows 10
Install numpy on Marvericks
Install python on windows
Install enebular-agent on Chromebook
Install pycuda on Windows10
Install mecab-python on CentOS
Install Python 2.7.3 on CentOS 5.4
Install aws-cli on MacPorts
Install pygraphviz on Windows 10
Install Docker on AWS
Install Python 3.3 on Ubuntu 12.04
Install Chainer 1.5.0 on Windows
Install Python 3.4 on Mac
Install Caffe on Mac
Install Theano on Ubuntu 12.04
Install pyenv on OSX
Install mecab on mac
Install awscli on centos7
Install angr on Ubuntu 18.04
Install Chainer on CentOS 6.7
Install mecab-python on Mac
Install pip / pip3 on Ubuntu
Install Python 3.6 on Docker
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Install Bash on Ubuntu on Windows, Ruby, Python, Jupyter, etc.
Install Numpy on virtualenv on Windows
Install Minecraft on Arch Linux
Install cvxopt on 64bit Anaconda
Run Jupyter on Ubuntu on Windows
Install Scrapy on Raspbian (Jessie)
Install Python 3.8 on RHEL 8 (AppStream)
Install Linux on your Chromebox
Install watchdog on Windows + Python 3.3
Install Win-Kex (kali-linux) on Windows 10.
Install pygame on python3.4 on mac
Install tomcat 9 on Cent OS 8