しゅうせいちゅう

Jupyter Notebookの進化版 JupyterLab を扱います

pyenv/anacondaの仮想実行環境を作ってそこにインストールします
OSの環境は下記になります

[root@rockylinux9 ~]# cat /etc/redhat-release
Rocky Linux release 9.2 (Blue Onyx)
 
[root@rockylinux9 ~]# cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  535.43.02  Mon May 22 20:46:13 UTC 2023
GCC version:  gcc version 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
 
[root@rockylinux9 ~]#

各自のホームディレクトリに各種pythonアプリの(仮想)実行環境を用意するのではなく、
rootでアプリの一元管理させたいので「pyenv-anaconda」を使ってます.

pyenvでOS提供のpython,anaconda環境から離れ、そのpyenv上にanaconda環境を独自に敷いてます. ここでは「/apps/pyenv」を起点としています

git clone https://github.com/yyuu/pyenv.git /apps/pyenv
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
pyenv install anaconda3-2023.03
pyenv global anaconda3-2023.03
export PATH=$PYENV_ROOT/versions/anaconda3-2023.03/bin/:$PATH
conda update conda -y
 
(既に環境があるなら)
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
export PATH=$PYENV_ROOT/versions/anaconda3-2023.03/bin/:$PATH

まず、jupyterlabの実行環境を作ります. pyenv/anacondaの中なので仮想環境っていうのでしょうが仮想って微妙なので実行環境としています

[root@rockylinux9 ~]# conda create -n jupyterlab
 
[root@rockylinux9 ~]# source activate jupyterlab
 
(jupyterlab) [root@rockylinux9 ~]# conda install -c conda-forge jupyterlab
 
(jupyterlab) [root@rockylinux9 ~]# pip install environment_kernels
 
(jupyterlab) [root@rockylinux9 ~]# jupyter --version
Selected Jupyter core packages...
IPython          : 8.14.0
ipykernel        : 6.23.1
ipywidgets       : not installed
jupyter_client   : 8.2.0
jupyter_core     : 5.3.0
jupyter_server   : 2.6.0
jupyterlab       : 4.0.1
nbclient         : 0.8.0
nbconvert        : 7.4.0
nbformat         : 5.9.0
notebook         : not installed
qtconsole        : not installed
traitlets        : 5.9.0
(jupyterlab) [root@rockylinux9 ~]#
 
(jupyterlab) [root@rockylinux9 ~]# conda deactivate
 
[root@rockylinux9 ~]#

jupyterlabはpythonコードを実行する場で「kernel」という名称でcondaで作った別の実行環境をロードできます.
なので簡単にですが、python3.10実行環境、python3.11実行環境らを用意してみます

[root@rockylinux9 ~]# conda create -n py06 python=3.06 -y
[root@rockylinux9 ~]# conda create -n py10 python=3.10 -y
[root@rockylinux9 ~]# conda create -n py11 python=3.11 -y
[root@rockylinux9 ~]# conda create -n eman2.99.47 eman-dev==2.99.47 -c cryoem -c conda-forge
[root@rockylinux9 ~]# conda create -n topaz python=3.6 topaz -c tbepler -c pytorch -y
 
[root@rockylinux9 ~]# conda env list
# conda environments:
#
base                     /apps/pyenv/versions/anaconda3-2023.03
eman2.99.47              /apps/pyenv/versions/anaconda3-2023.03/envs/eman2.99.47
jupyterlab               /apps/pyenv/versions/anaconda3-2023.03/envs/jupyterlab
py06                     /apps/pyenv/versions/anaconda3-2023.03/envs/py06
py10                     /apps/pyenv/versions/anaconda3-2023.03/envs/py10
py11                     /apps/pyenv/versions/anaconda3-2023.03/envs/py11
topaz                    /apps/pyenv/versions/anaconda3-2023.03/envs/topaz
 
[root@rockylinux9 ~]#

以上「jupyterlab」以外にも「py10」と「py11」の他、「eman2.99.47」、「topaz」を入れてみた.
これらを「jupyterlab」から使ってみる
たぶんcryoSPARCも使えるのかなと

っでこれら実行環境をjupyterlabから利用するには「ipykernel」を中に仕込んでおく.
baseでjupyterlabを動かすなら不要な気がしますが、、、

[root@rockylinux9 ~]# conda activate py06
(py06) [root@rockylinux9 ~]# conda install ipykernel -y
(py06) [root@rockylinux9 ~]# conda deactivate
 
[root@rockylinux9 ~]# conda activate py10
(py10) [root@rockylinux9 ~]# conda install ipykernel -y
(py10) [root@rockylinux9 ~]# conda deactivate
[root@rockylinux9 ~]#
 
[root@rockylinux9 ~]# conda activate py11
(py11) [root@rockylinux9 ~]# conda install ipykernel -y
(py11) [root@rockylinux9 ~]# conda deactivate
[root@rockylinux9 ~]#
 
[root@rockylinux9 ~]# conda activate eman2.99.47
(eman2.99.47) [root@rockylinux9 ~]# conda install ipykernel -y
(eman2.99.47) [root@rockylinux9 ~]# conda deactivate
[root@rockylinux9 ~]#
 
[root@rockylinux9 ~]# conda activate topaz
(topaz) [root@rockylinux9 ~]# conda install ipykernel -y
(topaz) [root@rockylinux9 ~]# conda deactivate
[root@rockylinux9 ~]#

Environment Modules

「/apps/modulefiles/JupyterLab/4.0.1」

[root@rockylinux9 ~]# mkdir -p /apps/modulefiles/JupyterLab
 
[root@rockylinux9 ~]# vi /apps/modulefiles/JupyterLab/4.0.1
#%Module1.0
set          root /apps/pyenv/versions/anaconda3-2023.03/envs/jupyterlab
prepend-path PATH $root/bin
 
[root@rockylinux9 ~]#

つかう

jupyterlabを起動させて、その中で「py06」環境をロードしてみる

面倒ですが、今度はユーザ側でjupyterlabでロードする環境を設定します

[saber@rockylinux9 ~]$ module use /apps/modulefiles/
[saber@rockylinux9 ~]$ module load JupyterLab
 
[saber@rockylinux9 ~]$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.14.0
ipykernel        : 6.23.1
ipywidgets       : not installed
jupyter_client   : 8.2.0
jupyter_core     : 5.3.0
jupyter_server   : 2.6.0
jupyterlab       : 4.0.1
nbclient         : 0.8.0
nbconvert        : 7.4.0
nbformat         : 5.9.0
notebook         : not installed
qtconsole        : not installed
traitlets        : 5.9.0
[saber@rockylinux9 ~]$
 
[saber@rockylinux9 ~]$ jupyter lab --generate-config
Writing default config to: /home/saber/.jupyter/jupyter_lab_config.py
[saber@rockylinux9 ~]$

ここで得られた「jupyter_lab_config.py」を修正します. 修正箇所は「c.ServerApp.ip」でいいかと.

[saber@rockylinux9 ~]$ vi /home/saber/.jupyter/jupyter_lab_config.py
 :
c.ServerApp.ip = '*'
 :
#c.NotebookApp.kernel_spec_manager_class='environment_kernels.EnvironmentKernelSpecManager'
#c.EnvironmentKernelSpecManager.conda_env_dirs=['/apps/pyenv/versions/anaconda3-2023.03/envs/']
 
[saber@rockylinux9 ~]$

ここでは「ipykernel」を入れた2つ「py06」と「py10」を定義します

[saber@rockylinux9 ~]$ conda activate py06
(py06) [saber@rockylinux9 ~]$ python -m ipykernel install --user --name py06 --display-name py06
Installed kernelspec py06 in /home/saber/.local/share/jupyter/kernels/py06
(py06) [saber@rockylinux9 ~]$ conda deactivate
[saber@rockylinux9 ~]$
 
[saber@rockylinux9 ~]$ conda activate py10
(py10) [saber@rockylinux9 ~]$ python -m ipykernel install --user --name py10 --display-name py10
Installed kernelspec py10 in /home/saber/.local/share/jupyter/kernels/py10
(py10) [saber@rockylinux9 ~]$
(py10) [saber@rockylinux9 ~]$ conda deactivate
[saber@rockylinux9 ~]$

jupyterlabを起動させます.

[saber@rockylinux9 ~]$ conda activate jupyterlab
(jupyterlab) [saber@rockylinux9 ~]$ jupyter lab
[I 2023-06-05 03:27:23.051 ServerApp] Package jupyterlab took 0.0000s to import
 :
[I 2023-06-05 03:27:23.182 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2023-06-05 03:27:31.784 ServerApp]
 
    To access the server, open this file in a browser:
        file:///home/saber/.local/share/jupyter/runtime/jpserver-4214-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=a22be4b390054261fbc6dfdd390f6261682f46fcb4f624d8
        http://127.0.0.1:8888/lab?token=a22be4b390054261fbc6dfdd390f6261682f46fcb4f624d8
[I 2023-06-05 03:27:31.793 ServerApp] Skipped non-installed server(s): bash-language-server, (略
 :

となってサーバ側(rockylinux9)のブラウザが立ち上がりますが、それは閉じて、

http://rockylinux9:8888/lab?token=a22be4b390054261fbc6dfdd390f6261682f46fcb4f624d8

としてアクセスします.

2023y06m05d_033240609.png

独自の実行環境「py10」が選べるようになります

使ってみる

アプリをインストールしたので、次は各自のユーザアカウントで 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」を修正するのですが、

とかでしょうか。パスワードは生のままでは定義できないようで、ハッシュされた文字列を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'
 
 ## Jinja environment に渡される追加の引数を指定します。
 #  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」にアクセスします
2021y09m05d_195824490.png
と表記され、先ほどハッシュ化文字列を作る際に使用した文字列(パスワード)を入力します
すると今夏画面になります

2021y09m05d_200107975.png

メモ

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」が使えるようになります

最新の60件
2025-04-27 2025-04-26 2025-04-25 2025-04-24 2025-04-17 2025-04-15 2025-04-13 2025-04-02 2025-04-01 2025-03-31 2025-03-29 2025-03-28 2025-03-27 2025-03-26 2025-03-23 2025-03-22 2025-03-20 2025-03-17 2025-03-16 2025-03-15 2025-03-06 2025-03-03 2025-03-01 2025-02-18 2025-02-17 2025-02-14 2025-02-12 2025-02-03 2025-02-02 2025-01-27 2025-01-26 2025-01-25 2025-01-24 2025-01-23

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-06-06 (火) 02:18:45