LoginSignup
28
39

More than 3 years have passed since last update.

jupyter labをリモートから使う

Last updated at Posted at 2019-01-29

環境

Ubuntu 18.04.1
python 3.6.7、
jupyter 4.4.0
jupyter notebook 4.4.0
jupyter lab 0.35.4
※ちょっと古くなってきたから最新環境ではどうなるか・・

インストール

※ jupyter等のインストールはaptとpipで行う。

環境設定

1. notebook_config.pyの作成

$ jupyter notebook --generate-config  (「jupyter lab --generate-config」でもok)
configファイル(~/.jupyter/jupyter_notebook_config.py)を作成。(~/はホームディレクトリ)

2. ipythonを実行、下記のコマンドでパスワードのハッシュ値を生成

$ ipython
In [1]: from IPython.lib import passwd
In [2]: passwd()

ここでパスワードを入力するとハッシュ値が生成(sha1:XXXXXXXXXXX)されるので、
そちらをコピーして、テキストファイルなどに保存。

3. ~/.jupyter/jupyter_notebook_config.pyの末尾に下記を記載。

~/.jupyter/jupyter_notebook_config.py

c = get_config()
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.ip = '0.0.0.0'              #(過去バージョンでは'*'指定だったけど今はだめみたい。)
c.NotebookApp.open_browser = False
c.NotebookApp.port = 9999                 #(任意)
c.NotebookApp.password = 'sha1:XXXXXXXXXXX'   #(#先ほど保存したハッシュ値を記載)

4. 起動してみる

$ jupyter lab
下記みたいな表示が出ていれば成功。

 JupyterLab server extension not enabled, manually loading...
 JupyterLab extension loaded from /home/xxxx/.local/lib/python3.6/site-packages/jupyterlab
 JupyterLab application directory is /home/xxxx/.local/share/jupyter/lab
 Serving notebooks from local directory: /home/xxxx/.jupyter
 The Jupyter Notebook is running at:
 http://(サーバ名 or 127.0.0.1):9999/
 Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

※ 起動スクリプトに下記を登録しておけば、reboot時に自動で立ち上がるようになる。
nohup jupyter lab &

5. リモートからアクセス

ブラウザから下記のURLでアクセス
http://[サーバIP]:9999/

パスワードを求められるはずなので、ハッシュ値作成の際使用したパスワードを入力。

最後に

jupyterは基本的にローカルに立てて使うものらしいで、
サーバへのインストール、リモートアクセス許可についてはセキュリティを考えながら実施するべき。

28
39
1

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
28
39