LoginSignup
1
6

More than 3 years have passed since last update.

Jupyter Notebook / Labを立ち上げてパスワードを設定するシンプルな方法

Last updated at Posted at 2020-10-05

はじめに

QiitaでもJupyterにパスワードを設定する方法は既出ですが、「この方法でやっておけば間違いない。簡単、しかも安全」というものがシンプルに書かれていたらなぁと思いました。
Jupyter Notebookサーバーを一から立てる人の参考になれば嬉しいです。

一応、Jupyterサーバーのインストールから。

前提

  • pip が利用できること

Jupyter Notebook サーバーを立ち上げる

terminal
$ pip install jupyter
$ jupyter notebook --port=8888 # ポートを指定したい場合

Jupyter Lab サーバーを立ち上げる

terminal
$ pip install jupyterlab
$ jupyter labextension install jupyterlab-plotly # Jupyter LabでPlotlyを使う場合(詳細は後述)
$ jupyter lab --port=8888 # ポートを指定したい場合

パスワードを設定する

自分でハッシュ化したり、パスワードを平文で書いたりする必要がなく、キーボード入力で自動で暗号化して保存してくれます。楽ちんですね。
参照: 公式ドキュメント

terminal
$ jupyter notebook password
Enter password: 
Verify password:
[NotebookPasswordApp] Wrote hashed password to $HOME/.jupyter/jupyter_notebook_config.json

余談

設定ファイルを生成する

サーバー起動時にブラウザを立ち上げたくないなどの設定は、このファイルを直接編集すればOKです。
やり方は Jupyter Notebook / Lab 共通です。

terminal
$ jupyter notebook --generate-config
Writing default config to: $HOME/.jupyter/jupyter_notebook_config.py

# 実際には$HOMEとは表示されません。ご使用の環境のホームディレクトリが表示されます。

Jupyter LabでPlotlyを使うなら必要な設定

Jupyter LabでPlotlyのグラフを描写しようとすると、表示されないことがあります。jupyter コマンドでプラグインをインストールしましょう。グローバルで node コマンドが使えること前提です。

Plotly 公式ドキュメントJupyterLab Support (Python 3.5+) に書かれているとおりインストールを行います。

terminal
$ brew install node # macOSの場合
$ node --version
v14.13.0
$ jupyter labextension install jupyterlab-plotly
1
6
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
6