LoginSignup
3
5

More than 5 years have passed since last update.

Jupyter-gopherlab

Posted at

Jupyter-gopherlab

JupyterのGoカーネルを探すと次の選択肢があります。

Ubuntu 16.04ではgolang 1.6.2が入るため、ここではgopherlabの環境を構築します。

準備

libzmq-4.x系を要求されますが、Ubuntu 16.04ではlibzmqのバージョンが古いため、次の手順でlibzmqをインストールする必要があります。

/etc/apt/source.list.d/zeromq.list
deb http://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/ ./

上記ファイルを作成し、libzmq3-devをインストールします。(libzmq3-devでlibzmq-4.xが入ります。)

wget https://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/Release.key -O- | sudo apt-key add
sudo apt update
sudo apt install libzmq3-dev

環境構築

https://github.com/fabian-z/gopherlab にしたがって粛々とkernelを作成します。

go get github.com/fabian-z/gopherlab
mkdir -p ~/.local/share/jupyter/kernels/gopherlab
cp -r $GOPATH/src/github.com/fabian-z/gopherlab/kernel/* ~/.local/share/jupyter/kernels/gopherlab/
cp -a $GOPATH/bin/gopherlab ~/.local/share/jupyter/kernels/gopherlab/
sed -i "s#/go/bin/gopherlab#$HOME/.local/share/jupyter/kernels/gopherlab/gopherlab#g" $HOME/.local/share/jupyter/kernels/gopherlab/kernel.json

いつものようにjupyter-notebookを起動すると、新規NotebookのところにGo (gopherlab)と追加されています。

image.png

右上にGopherくんが表示されます。

image.png

kernel errorが発生した場合、GOPATH等が通っていない可能性がありますので、jupyter notebookの吐き出すエラーログ等をご確認下さい。

Hello World

import "fmt"
fmt.Printf("Hello world\n")

image.png

セルの間隔が少し気になりますね…。

Goをインタプリタで扱うことができるため、大変学習効率が良いと思われます。

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5