Go

Run Go in Jupyter Notebook

Jupyer Notebook is a effective tool for newbies to learn and practice a brand new programming language.

Posted by Pele on December 20, 2023

Jupyer Notebook is a effective tool for newbies to learn and practice a brand new programming language. It is easy to install and use. This article will show you how to install and run Go in Jupyter Notebook on macOS.

1. Install Go and Jupyter Notebook

# Install Go
brew install go

# Install Jupyter Notebook
pip3 install jupyter

2. Install Go kernel for Jupyter Notebook

gophernotes - Use Go in Jupyter notebooks and nteract

  go install github.com/gopherdata/gophernotes@v0.7.5
  mkdir -p ~/Library/Jupyter/kernels/gophernotes
  cd ~/Library/Jupyter/kernels/gophernotes
  cp "$(go env GOPATH)"/pkg/mod/github.com/gopherdata/gophernotes@v0.7.5/kernel/*  "."
  chmod +w ./kernel.json # in case copied kernel.json has no write permission
  sed "s|gophernotes|$(go env GOPATH)/bin/gophernotes|" < kernel.json.in > kernel.json

To confirm that the gophernotes binary is installed in GOPATH, execute it directly:

 (go env GOPATH)"/bin/gophernotes

and you should see the following:

2017/09/20 10:33:12 Need a command line argument specifying the connection file.

3. Run Jupyter Notebook

  • Start the jupyter notebook serve
    jupyter notebook
    
  • mSelect Go from the kernel menu.

  • Have fun!