Jupyter Notebookの進化版 JupyterLab を扱います
組み込み方はいろいろでここでは docker を使わないでOS上に直に Jupyter Labを載せて、
ユーザ各自のコマンド実行で Jupyter Lab を利用するようにします。
これはrootが用意したJupyterLabを使う前提です. 本家がバージョンアップしているのに管理者がupしてくれないとかで支障があるなら自身のホームディレクトリにanacondaの沼を作るか、docker/Singularityとかで対処したほうがいいのかも. ここではEnvironment Modulesを使うので管理者はバージョン毎にmodulefileを用意するといった想定です
pyenv/anacondaの仮想実行環境を作ってそこにインストールします
OSの環境は下記になります
[root@s ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@s ~]# cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 470.42.01 Tue Jun 15 21:26:37 UTC 2021
GCC version: gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
[root@s ~]# /usr/local/cuda/bin/nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0
[root@s ~]#
このサイトではcrYOLOとかで既にanaconda環境が準備されいます. なので下記のみを実行してanaconda環境に移る.
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
eval "$(pyenv init - --no-rehash)"
export PATH=$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH
(condaが古いと言われたら)
conda update -n base -c defaults conda
そして環境を作ります
[root@s ~]# conda create -n jupyterlab
[root@s ~]# source activate jupyterlab
(jupyterlab) [root@s ~]# conda install -c anaconda tensorflow-gpu
(jupyterlab) [root@s ~]# conda install -c conda-forge jupyterlab
インストールが完了して、確認してみます
(jupyterlab) [root@s ~]# jupyter --help
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir] [--paths] [--json] [--debug] [subcommand]
Jupyter: Interactive Computing
positional arguments:
subcommand the subcommand to launch
optional arguments:
-h, --help show this help message and exit
--version show the jupyter command's version and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable format.
--json output paths as machine-readable json
--debug output debug information about paths
Available subcommands: bundlerextension console kernel kernelspec lab labextension labhub migrate nbclassic nbconvert
nbextension notebook qtconsole run server serverextension troubleshoot trust
(jupyterlab) [root@s ~]#
(jupyterlab) [root@s ~]# jupyter --version
jupyter core : 4.7.1
jupyter-notebook : 6.4.3
qtconsole : not installed
ipython : 7.27.0
ipykernel : 6.3.1
jupyter client : 7.0.2
jupyter lab : 3.1.10
nbconvert : 6.1.0
ipywidgets : not installed
nbformat : 5.1.3
traitlets : 5.1.0
(jupyterlab) [root@s ~]#
Environment Modules †
「/etc/modulefiles/JupyterLab/3.1.10」
#%Module1.0
set root /apps/pyenv/versions/anaconda3-5.3.1/envs/jupyterlab
prepend-path PATH $root/bin
使ってみる †
アプリをインストールしたので、次は各自のユーザアカウントで JupyterLab を起動させます.
まずはmoduleコマンドで環境をロードします
[illya@s ~]$ module load JupyterLab
次に初回だけですが、セットアップファイルを取得します
[illya@s ~]$ jupyter lab --generate-config
Writing default config to: /home/illya/.jupyter/jupyter_lab_config.py
[illya@s ~]$
この「/home/illya/.jupyter/jupyter_lab_config.py」を修正するのですが、
- 実行ホスト以外からのアクセスを許可するか(リモートアクセス許可)
- パスワードでアクセス制御するか
- リモートアクセス時のport番号は
とかでしょうか。パスワードは生のままでは定義できないようで、ハッシュされた文字列をipython経由で得るみたい
[illya@s ~]$ ipython
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.27.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password: <--パスワードを入力
Verify password:
Out[2]: 'sha1:055bde1f9548:057b18ee2742d8b17xxxxxxxxxxxxxxxxxxxxxxxxxx' <-- 得られた文字列
In [3]: quit()
[illya@s ~]$
っで「/home/illya/.jupyter/jupyter_lab_config.py」を修正します
| --- /home/illya/.jupyter/jupyter_lab_config.py.orig 2021-09-05 19:44:34.401992934 +0900
+++ /home/illya/.jupyter/jupyter_lab_config.py 2021-09-05 19:55:52.273771152 +0900
@@ -755,7 +755,7 @@
## The IP address the Jupyter server will listen on.
# Default: 'localhost'
-# c.ServerApp.ip = 'localhost'
+c.ServerApp.ip = '0.0.0.0'
# Default: {}
@@ -854,7 +854,7 @@
# The string should be of the form type:salt:hashed-
# password.
# Default: ''
-# c.ServerApp.password = ''
+c.ServerApp.password = 'sha1:055bde1f9548:057b18ee2742d8b17xxxxxxxxxxxxxxxxxxxxxxxxxx'
## Forces users to use a password for the Jupyter server.
# This is useful in a multi user environment, for instance when
@@ -867,7 +867,7 @@
## The port the server will listen on (env: JUPYTER_PORT).
# Default: 0
-# c.ServerApp.port = 0
+c.ServerApp.port = 8787
## The number of additional ports to try if the specified port is not available
# (env: JUPYTER_PORT_RETRIES).
|
っでJupyter Labを起動します
[illya@s ~]$ jupyter lab
[I 2021-09-05 19:57:33.736 ServerApp] jupyterlab | extension was successfully linked.
[I 2021-09-05 19:57:33.756 ServerApp] Writing Jupyter server cookie secret to /home/illya/.local/share/jupyter/runtime/jupyter_cookie_secret
[I 2021-09-05 19:57:33.894 ServerApp] nbclassic | extension was successfully linked.
[I 2021-09-05 19:57:33.937 ServerApp] nbclassic | extension was successfully loaded.
[I 2021-09-05 19:57:33.938 LabApp] JupyterLab extension loaded from /apps/pyenv/versions/anaconda3-5.3.1/envs/jupyterlab/lib/python3.8/site-packages/jupyterlab
[I 2021-09-05 19:57:33.938 LabApp] JupyterLab application directory is /share/apps/pyenv/versions/anaconda3-5.3.1/envs/jupyterlab/share/jupyter/lab
[I 2021-09-05 19:57:33.941 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-09-05 19:57:33.941 ServerApp] ローカルディレクトリからノートブックをサーブ: /home/illya
[I 2021-09-05 19:57:33.941 ServerApp] Jupyter Server 1.10.2 is running at:
[I 2021-09-05 19:57:33.941 ServerApp] http://s:8787/lab
[I 2021-09-05 19:57:33.941 ServerApp] or http://127.0.0.1:8787/lab
[I 2021-09-05 19:57:33.941 ServerApp] サーバを停止し全てのカーネルをシャットダウンするには Control-C を使って下さい(確認をスキップするには2回)。
[W 2021-09-05 19:57:33.960 ServerApp] ウェブブラウザが見つかりません: could not locate runnable browser
(フォアグランドで動きます)
ここでブラウザを空けて「http://s:8787/lab」にアクセスします

と表記され、先ほどハッシュ化文字列を作る際に使用した文字列(パスワード)を入力します
すると今夏画面になります

メモ †
https://github.com/jupyter/nbconvert/issues/1594 から
chmod -R 777 /usr/share/jupyter/nbconvert/templates/
chmod -R 777 /usr/local/share/jupyter/nbconvert/templates/
とあるが、、微妙
「jupyter lab」で起動させるとフォアグランドで稼働します。っでこれをバックグランドで、しかもマシンをログアウトしても
そのまま稼働し続けさせるには「nohup」を使って「nohup jupyter lab &」とする. コマンドのログは nohup.out に追記される.
「nohup」で動かしたプロセスを停止するには「ps -ef |grep jupyterlab」で出てくるpidを「kill」するしかないみたい.
JupyterLabからRを使うには †
起動しているJupyterLab があるなら停止します。その後に下記の作業を行います
まず、インストールは2系統あるようで1つはGitHubから最新を持ってくる方法、もうひとつはCRAN経由で全て行う方法みたい
(GitHubを活用)「install.packages('devtools')」「devtools::install_github('IRkernel/IRkernel')」「IRkernel::installspec()」
(cranを活用)「install.packages('IRkernel')」「IRkernel::installspec()」
ここではcranを使って入れています
[illya@s ~]$ module load R
[illya@s ~]$ module load JupyterLab
[illya@s ~]$ R
> install.packages('IRkernel')
install.packages("IRkernel") で警告がありました:
'lib = "/share/apps/R-4.1.1/lib64/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library
‘/home/illya/R/4.1.1’
to install packages into? (yes/No/cancel) yes
:
:
> IRkernel::installspec(name = 'ir411', displayname = 'R 4.1.1')
[InstallKernelSpec] Installed kernelspec ir411 in /home/illya/.local/share/jupyter/kernels/ir411
> quit()
Save workspace image? [y/n/c]: n
[illya@s ~]$
この後に JupyterLab を起動するとJupyterLab から「R」が使えるようになります