用Mac安装jupyter XXX(iruby、R、nodes、go)

我通常使用Python的Jupyter,但由于它支持其他语言,所以我也尝试安装了以下语言:
– A) Ruby
– B) R
– C) Nodes
– D) Go

结果,在同一个目录下有python、ruby、R、go、nodejs的.ipynb文件时,会让人感到混乱(笑)。

jupyter-many.png

安装Jupyter

首先,从安装Jupyter Notebook(以及Python3)开始(如果已经安装请跳过此步骤)。

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python3
pip3 install jupyter


完成安装后,

jupyter notebook

服务器开始运行后,稍等片刻浏览器会自动打开http://localhost:8888。此外,如果在后台启动时加上&符号,后续会很麻烦需要手动kill(使用命令”kill `ps -ef | grep jupyter | awk {‘print $2’}`”来获取第二列并消除。是否有更好的方法)。

使用Mac上的Python时,我发现有很多文章谈到从pyenv安装Python,或者安装anaconda以获取各种选项。但是,如果只是普通地使用,我认为使用brew安装Python3会更方便。如果需要使用Python2,可以使用python/pip,如果需要使用Python3,可以使用python3/pip3,无需切换。这样就不会被anaconda的版本更新所干扰。

A) 使用Jupyter运行Ruby(IRuby)。

jupyter-ruby.png
brew install zeromq czmq
gem install rbczmq -- --with-system-libs
gem install iruby

gem install nyaplot # これはjupyterとか関係ないが欲しくて入れた。

这是新的话题? nyaplot也可以运行并且满意(但是,期待的3D绘图时出现了错误!
添加输出时遇到了Javascript错误!
类型错误:未定义的对象(评估’ext.pane’不是一个对象)
在浏览器的Javascript控制台中查看更多详细信息。
为什么会这样呢…)

我参考了下面文章中关于安装rbczmq的方法。

请使用母语汉语进行以下内容的改写,只需提供一种选项:

http://qiita.com/mrkn/items/78196ed59266f58dcb64

链接:http://qiita.com/mrkn/items/78196ed59266f58dcb64

(备注)另外,对于Mac来说,也有人说可以使用ffi-rzmq代替rbczmq,例如:

以下是一个选项的中文本地化翻译:

http://qiita.com/domitry/items/aa348caf993e876a7be5

# 自分の環境ではffi-rzmqでは動作せず、、
gem install ffi-rzmq
gem install iruby

起初我尝试启动它,但很快就出现了Dead kernel的错误,并且无法正常运行。最终,我卸载了ffi-rzmq宝石,并按照上述方法安装了rbczmq。

无论您输入以下哪个选项,都会启动相同的应用程序:
– iruby 笔记本
– python 笔记本
– jupyter 笔记本

另外,我记得是通过rbenv安装了Ruby(详细情况我已经忘记了)。

brew install rbenv
...

B) 使用Jupyter运行R编程语言。

jupyter-R.png

请给出以下链接的中文释义:

https://github.com/IRkernel/IRkernel

根据上述公式,启动R。

install.packages(c('repr', 'IRdisplay', 'crayon', 'pbdZMQ', 'devtools'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()  # to register the kernel in the current R installation

安装完成后,在jupyter notebook上选择R,然后尝试运行plot(iris)。

在其他网站上介绍了其他方法,但尝试后却没有成功。之后我查阅了官方网站并进行了操作。顺便提一下,我认为R已经下载并安装了相关包。

如果要在brew上安装R,则必须指定tap homebrew/science,否则会提示找不到。

brew tap homebrew/science
brew install R

此外,探索性分析环境的R出现了。引人注目。

https://exploratory.io:
https://exploratory.io

http://qiita.com/21-Hidetaka-Ko/items/0c746d84d568113536bf:
http://qiita.com/21-Hidetaka-Ko/items/0c746d84d568113536bf

C) 用Jupyter进行nodejs操作

jupyter-nodejs.png

请使用下面的github链接查看Jupyter-Node.js的相关信息:
https://github.com/notablemind/jupyter-nodejs

git clone git@github.com:notablemind/jupyter-nodejs.git
因为无法通过验证,所以我使用以下方式克隆:
git clone https://github.com/notablemind/jupyter-nodejs.git

接下来就这样

git clone https://github.com/notablemind/jupyter-nodejs.git
cd jupyter-nodejs
mkdir -p ~/.ipython/kernels/nodejs/
npm install && node install.js
make

完成。途中で、何か言われた気がしたけれど、普通に動いている。console.log(‘hello’)を試してみましょう。
また、nodejsのインストールは、

brew install node

D-1) 使用Jupyter (Docker 版) 进行 Go 编程

jupyter-go.png

请提供以下链接的中文本地化版本:https://github.com/gopherds/gophernotes

我試著將它安裝在本地時發現步驟很麻煩(實際上並不是如此),所以我先嘗試用Docker。在Mac上的步驟如下:

docker pull dwhitena/gophernotes:latest
docker run --net host -d dwhitena/gophernotes jupyter notebook --no-browser --ip=0.0.0.0

找了很久也找不到(不论是在http://localhost:8888还是http://0.0.0.0:8888上都找不到)。

请将以下内容以中文进行引述,只需要一种选项:

https://github.com/gopherds/gophernotes/issues/43

需要进行端口映射(当然了)。8888端口已被本地的Jupyter占用,所以在这里使用9000端口。

docker run -p 9000:8888 -d dwhitena/gophernotes jupyter notebook --no-browser --ip=0.0.0.0

另外,在issues/43中,我使用了–rm参数。加上–rm参数后,可以通过CTRL-C停止和删除容器,非常方便。不过,重新启动后,之前的文件(Untitled.ipynb)会被删除,这是不好的。所以,我认为使用上述方法比较好。

如果它移动了,就通过9000号连接。
http://localhost:9000

选了New的话,试着写成fmt.Println(“你好, 世界”)

安装go的步骤如下:

brew install golang

从Docker官方网页下载(Docker.dmg)并安装。

D-2) 本地版用Jupyter编写Go。

docker为方便且启动迅速,但是放置大型镜像和容器并不有趣。因此,仍然选择安装在本地。再次,建议使用官方版。

请使用以下链接访问 Gophernotes 在 GitHub 上的项目:https://github.com/gopherds/gophernotes

查看。看起来有点麻烦,但实际上只是设置的摆放位置因人而异而已。首先,执行jupyter –data-dir命令,以确认自己的jupyter核心设置存放在哪里。对我来说,应该是在~Library/Jupyter。

jupyter --data-dir
/Users/xxx/Library/Jupyter

剩下的就是以下内容轻松进入。

go get golang.org/x/tools/cmd/goimports
go get -tags zmq_4_x github.com/gopherds/gophernotes

mkdir -p ~/Library/Jupyter/kernels/gophernotes
cp -r $GOPATH/src/github.com/gopherds/gophernotes/kernel/* ~/Library/Jupyter/kernels/gophernotes

此外,对于设置项(即jupyter –data-dir的输出)不是位于~Library/Jupyter,而是位于~/.ipython的用户,可按以下操作进行(其中go get部分不变)。

go get golang.org/x/tools/cmd/goimports
go get -tags zmq_4_x github.com/gopherds/gophernotes

mkdir ~/.ipython/kernels/gophernotes
cp -r $GOPATH/src/github.com/gopherds/gophernotes/kernel/* ~/.ipython/kernels/gophernotes/

似乎有ZeroMQ 2.2.x和ZeroMQ 4.x两个版本,但是由于无法使用ZeroMQ 2.2.x,所以选择了ZeroMQ 4.x。

D-3) 运行go

试一试,在https://golang.org这个官方网址上运行hello world程序,结果出现了死机的情况!

// mainを使おうとするとjupyterではDead kernelになって止まる!!
package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

貌似不可以在代码中使用”package main”之类的。可以使用以下方式,只需将”main”替换为”test”即可通过。

import "fmt"
func test() {
    fmt.Println("Hello, 世界")
}
test()

另外,据称fmt已经从一开始就被导入了,因此可以直接使用fmt.Println而无需导入”fmt”。

(仅供参考)在Mac上设置jupyter内核的位置是什么?

在我个人的情况下,

    • ruby、nodesは、~/.ipython/kernels/

 

    ir(=R)、gophernotes(=go)は、~Library/Jupyter/kernels/

我已经安装在~Library/Jupyter中。目前,似乎可以在~/.ipython/kernels/或~Library/Jupyter/kernels/都能运行。实际上,我最初把它放在了~/.ipython/kernels/中它也正常工作。之后,我错把位置放错了!于是用mv命令将它移动到了~Library/Jupyter/kernels/中。不管放在哪个位置,只要从一个位置移动到另一个位置,它都能正常运行。

广告
将在 10 秒后关闭
bannerAds