1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jupyter notebook を Dockからワンクリックで起動(macOS)

1
Posted at

Macで Jupyter notebookを使うのに,Terminal起動してコマンド入力するのが億劫なので,Dockに .commandファイルを登録して起動できるようにした。
いつも同じフォルダから起動したい人向け。

.commandファイルでJupyterを起動

次の内容のテキストファイルを作成。ファイル名を jupyter.command とする。

jupyter.command
# !/bin/sh
cd ~/notebook && jupyter notebook

ターミナルで実行権限をつける

chmod +x jupyter.command

jupyter.command ファイルをDockに入れる。

二重にJupyterを起動しないように改良

Jupyter notebook が起動しているかを調べて,すでに起動していたらブラウザで開き直す

jupyter.command
# 二重に開くのを避ける
jnlist=`jupyter notebook list --json`

if [ "x$jnlist" = 'x' ]; then
    # 起動しているのがなければ
    cd ~/notebook && jupyter notebook
    # 別の書き方
    # jupyter notebook --notebook-dir="~/notebook"
else
    # 起動していたら決め打ちでブラウザを開く
    open http://localhost:8888
fi

終了するには

終了コマンド

その1:起動したターミナルで control+C で終了
その2:jupyter notebook stopコマンドを実行(複数起動していても stopで1つしか止まらない)

自動終了させるオプション

http://jupyter-notebook.readthedocs.io/en/stable/config.html
https://github.com/jupyter/notebook/issues/1300

一定時間放置すると自動終了させるように設定できる。

  1. jupyter notebook の設定ファイルの作成
    jupyter notebook --generate-config コマンドを実行
    ~/.jupyter/jupyter_notebook_config.py が作成される
  2. 終了時間の指定
    jupyter_notebook_config.py ファイルの
    下記オプションで指定できる(単位は秒)
c.MappingKernelManager.cull_idle_timeout = 600
c.NotebookApp.shutdown_no_activity_timeout = 600
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?