Jupyter Notebook 安装 GO 内核

编辑于 2023-05-18 17:38 阅读 1919

普通安装

https://github.com/janpfeifer/gonb#linux-and-mac-installation

go install github.com/janpfeifer/gonb@latest && go install golang.org/x/tools/cmd/goimports@latest && go install golang.org/x/tools/gopls@latest && gonb --install

接着我用PyCharm/VS Code测试,报错了

fmt: package fmt is not in GOROOT (/usr/local/Cellar/go/1.19/src/fmt)

这就神奇了,我GoLand 中的几个项目都可以正常跑。于是我打开GoLand,选择一个项目,在终端输入

cuiwei@weideMacBook-Pro demo % echo $GOROOT

/usr/local/opt/go/libexec

结果发现和报错中的GOROOT值不一致。于是我重新设置了全局的GOROOT

vi ~/.zshrc
export GOROOT=/usr/local/opt/go/libexec

保存后,重新打开PyCharm/VS Code结果都好了🥳

docker 安装

docker pull janpfeifer/gonb_jupyter:latest
docker run -it --rm -p 8888:8888 -v "${PWD}":/home/jovyan/work janpfeifer/gonb_jupyterlab:latest

服务启动成功就可以访问 http://localhost:8899/lab

WX202305181643332x.png

如果不想用网页版,请继续往下看

配合PyCharm使用

这里介绍的是使用jupyter远程服务

上面docker启动janpfeifer/gonb_jupyter成功,会得到如下地址

http://127.0.0.1:8888/lab?token=d7455ae2e0478a620695814a8c70e4ae890942ea072b23be

粘贴到如下图的位置即可 jupyter server

结果是能正常跑,但语法飘红。。。(PyCharm肯定不支持GO🤣)

WX202305181640222x.png

配合VS Code使用

这里也是使用jupyter远程服务,如下

WX202305181632532x.png

效果还不错~

WX202305181638562x.png

参考

https://github.com/janpfeifer/gonb

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验