LoginSignup
10
10

More than 5 years have passed since last update.

OSX El CapitanにJupyterLabをインストールする

Last updated at Posted at 2016-08-09

pythonのインストール

2系と3系があり、今回は3系をインストールする。

$ brew install python3
$ python3 -V
Python 3.5.2

pip3が入っていることを確認

$ pip3 -V
pip 8.1.2 from /usr/local/lib/python3.5/site-packages (python 3.5)

jupyter本体のインストール

pip3 install jupyter

Jupyterの設定

$ jupyter notebook --generate-config
Writing default config to: /Users/(ユーザー名)/.jupyter/jupyter_notebook_config.py

上記で作成されたファイルをエディタで開いて編集。
該当箇所のコメントを外す。
今回はDropboxに作成したjupyterディレクトリを指定。

# root directory
c.NotebookApp.notebook_dir = '/Users/(ユーザー名)/Dropbox/jupyter'

# port
c.NotebookApp.port = 65432

Jupyterの起動

$ jupyter notebook

ブラウザが開いて立ち上がる。

JupyterLabのインストール

$ pip3 install jupyterlab
$ jupyter serverextension enable --py jupyterlab

JupyterLabの起動

$ jupyter lab

追加カーネルのインストール

ここまででpython3のみ扱えるようになっているが、各種カーネルを入れることによって、いろいろな言語に対応可能になる。
今回はJupyterLab対応の、Javascript、Scala、Golang、PHP、Bash用カーネルを入れる。

これ以外のカーネルのリストは以下を見る。
IPython kernels for other languages · ipython/ipython Wiki

Javascript

n-riesco/ijavascript: IJavascript is a javascript kernel for the Jupyter notebook

$ brew install npm pkg-config zeromq
$ npm -v
3.10.3
$ node -v
v6.3.1
$ npm install -g ijavascript

初回だけ以下を実行。
ブラウザでnotebookが起動するので、終了する。
以後は jupyter lab でOK。

$ ijs

Scala

alexarchambault/jupyter-scala: Lightweight Scala kernel for Jupyter / IPython 3

$ brew install scala
$ curl -L -o jupyter-scala https://git.io/vrHhi && chmod +x jupyter-scala && ./jupyter-scala && rm -f jupyter-scala

Golang

fabian-z/gopherlab: It's time to use Go in notebooks. Fork from the original gophernotes project, supporting message spec v5 (JupyterLab)

$ brew install go
$ go version
go version go1.6.3 darwin/amd64
$ go get golang.org/x/tools/cmd/goimports
$ go get github.com/fabian-z/gopherlab
$ mkdir -p ~/Library/Jupyter/kernels/gopherlab
$ cp -r $GOPATH/src/github.com/fabian-z/gopherlab/kernel/* ~/Library/Jupyter/kernels/gopherlab
$ jupyter --data-dir

~/Library/Jupyter/kernels/gopherlab/kernel.jsonを編集。
argvをインストールしたパスに合わせる。

~/Library/Jupyter/kernels/gophernotes/kernel.json
{
    "argv": [
      "/Users/(ユーザー名)/go/bin/gopherlab",
      "{connection_file}"
      ],
    "display_name": "Golang",
    "language": "go",
    "name": "go"
}

PHP

Litipk/Jupyter-PHP: A PHP Kernel for Jupyter

$ brew install homebrew/php/php56 homebrew/php/php56-zmq composer
$ php -v
PHP 5.6.24 (cli) (built: Jul 22 2016 02:41:22) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

忘れずにtimezoneを設定する。

/usr/local/etc/php/5.6/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tokyo

Jupyter-PHP's Installer by Litipk
から、jupyter-php-installer.pharをダウンロードしておく。

$ php ./jupyter-php-installer.phar install
The Jupyter-PHP kernel has been successfully installed.

Bash

takluyver/bash_kernel: A bash kernel for IPython

$ pip3 install bash_kernel
$ python3 -m bash_kernel.install

インストール済みのカーネルを確認

$ jupyter kernelspec list
  python3        /usr/local/lib/python3.5/site-packages/ipykernel/resources
  bash           /Users/maccotsan/Library/Jupyter/kernels/bash
  gopherlab      /Users/maccotsan/Library/Jupyter/kernels/gopherlab
  javascript     /Users/maccotsan/Library/Jupyter/kernels/javascript
  jupyter-php    /Users/maccotsan/Library/Jupyter/kernels/jupyter-php
  scala211       /Users/maccotsan/Library/Jupyter/kernels/scala211

拡張機能の追加

JupyterLabではまだ使えない(notebookのみ)が、あると便利な拡張機能を入れておく。
実際、これらが使えるようになるまではnotebookの方が良いかも・・・。
ipython-contrib/jupyter_contrib_nbextensions: A collection of various different notebook extensions for Jupyter

$ pip3 install jupyter_contrib_nbextensions
$ jupyter contrib nbextension install --user
$ jupyter nootbook

http://localhost:65432/nbextensions/ にアクセスして有効にする拡張機能を選ぶ。

有効にしたもの

・Nbextensions edit menu item(メニューに拡張機能設定画面へのリンク追加)
・AutoSaveTime(ファイルの自動保存)
・Move selected cells(セルの上下入れ替えボタンを追加)
・Rubberband(シフトキー押しながらドラッグで複数セル選択)
・Table of Contents (2)(目次を自動生成)
・Search-Replace(検索、置換)
・ExcuteTime(コードの実行時間測定)
・Collapsible Headings(ヘッダの折りたたみ)
・Codefolding(コードの折りたたみ)
・Drag and Drop(ドラッグアンドドロップで画像追加)

参考

Installing Jupyter Notebook — Jupyter Documentation 4.1.1 alpha documentation

MacでPython使う時の最低限のメモ(Homebrew編) - Qiita

Jupyter Notebookをインストール・設定して勉強ノート作成環境をつくる [Mac] - Qiita

Jupyter Notebook(IPython)のインストールと始め方 - TASK NOTES

Jupyter Notebookの次世代版、JupyterLabのこれが凄いポイントの紹介 - のんびりしているエンジニアの日記

Jupyter Notebookの拡張機能を使ってみる - はしくれエンジニアもどきのメモ

10
10
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
10
10