Pythonで機械学習を学ぶために、Jupyter Lab をローカル環境に立ち上げた。そのときのメモ。

STEP 1. インストール

anacondaをインストールする。インストールファイルは、以下のURLから手に入る。

Free Download

STEP 2. 設定ファイルの生成

以下のコマンドで~/.jupyter/jupyter_notebook_config.pyという設定ファイルを生成する。

$ jupyter notebook --generate-config

STEP 3. パスワード

デフォルトでは、トークン認証になっているのでパスワード認証に切り替える。まずは、以下のコマンドでパスワードを生成する。

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

$ more /Users/username/.jupyter/jupyter_notebook_config.json
{
  "NotebookApp": {
    "password": "sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed"
  }
}

次に生成したパスワード(ハッシュ化されている)をSTEP 1.の設定ファイルに追加する。

## Hashed password to use for web authentication.
#  
#  To generate, type in a python/IPython shell:
#  
#    from notebook.auth import passwd; passwd()
#  
#  The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

STEP 4. その他の細かい設定

    起動時に、Jupyter Lab が自動的に開かないようにする。
## Whether to open in a browser after starting. The specific browser used is
#  platform dependent and determined by the python standard library `webbrowser`
#  module, unless it is overridden using the --browser (NotebookApp.browser)
#  configuration option.
c.NotebookApp.open_browser = False
    ポート番号を変更する。
## The port the notebook server will listen on.
c.NotebookApp.port = 18888
    グラフを描画できるようにする。
## DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
c.NotebookApp.pylab = 'disabled'

STEP 5. 起動

以下のコマンドで、バックグラウンドで起動させる。

$ nohup jupyter lab &

プロセスを停止したい場合は、以下のようにする。

$ lsof -i:8888
$ kill -9 [process id]

感想

必要なものはanacondaが一括で提供してくれるので、Pythonで機械学習を学ぶ環境はかなり簡単に手に入ることがわかった。ただ各種の設定などは少し手間がかかったので共有しようと思った。

参考

    Running a notebook server
广告
将在 10 秒后关闭
bannerAds