Jupyterhub/labのGit extensionを入れるときのメモ


はじめに

Jupyterhub/labにGit extensionを入れるときにちょっと引っかかったので、その時の自分用のメモ。
また、Jupyterhub/labのインストール&起動についてはこちらをご参照ください。

環境


$sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.6
BuildVersion:   17G14042

$docker --version
Docker version 20.10.0, build 7287ab3

やること

Jupyterhub / labにGit extensionを導入します。

やったこと

Jupyterlab 3.0.7の場合

最初にdockerからJupyterhubのイメージを取得して起動します。


docker run -it -p 8000:8000 --name jupyterhub jupyterhub/jupyterhub bash

こちらを参考に設定していきます。

apt update
apt install python3 python3-pip npm nodejs libnode64 vim git
npm install -g configurable-http-proxy
pip3 install -U pip
pip3 install jupyterlab==2.2.9
pip3 install jupyterlab-git==0.23.3
jupyterhub --generate-config
vim jupyterhub_config.py 

jupyterhub_config.pyに以下を追加します。

jupyterhub_config
c.Spawner.default_url = '/lab'
c.Spawner.notebook_dir = '~/notebook'
c.Authenticator.admin_users = {'testadmin'}
c.Authenticator.allowed_users = {'testuser01'}

ログイン用のユーザを作成しておきます。

adduser testadmin
mkdir -p -m 777 /home/testadmin/notebook
chown testadmin: /home/testadmin/notebook
adduser testuser01
mkdir -p -m 777 /home/testuser01/notebook
chown testuser01: /home/testuser01/notebook

起動する前に各ライブラリのバージョンを確認しておきます。


root@62ecd14f5e8a:/srv/jupyterhub# jupyterhub --version
1.3.0
root@62ecd14f5e8a:/srv/jupyterhub# jupyter-lab --version
3.0.7
root@62ecd14f5e8a:/srv/jupyterhub# python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from  jupyterlab_git import __version__ as ver
>>> print(ver)
0.23.3

ここでJupyterhubを起動します。

jupyterhub jupyterhub_config.py 

ただし、Git extensionがうまく動作していません。

Jupyterlab-gitのドキュメントを確認すると、サーバ側とフロント側のextensionを確認するようにとのことなので、まずサーバ側のextensionを確認します。


root@62ecd14f5e8a:/srv/jupyterhub# jupyter server extension list
Config dir: /root/.jupyter

Config dir: /usr/etc/jupyter

Config dir: /usr/local/etc/jupyter
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.7 OK
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  OK

Git extensionが見当たらないので、jupyterlab-gitを有効化します。


root@62ecd14f5e8a:/srv/jupyterhub# jupyter server extension enable --py jupyterlab_git
Enabling: jupyterlab_git
- Writing config: /usr/etc/jupyter
    - Validating jupyterlab_git...
      jupyterlab_git 0.23.3 OK
    - Extension successfully enabled.
root@62ecd14f5e8a:/srv/jupyterhub# jupyter server extension list
Config dir: /root/.jupyter

Config dir: /usr/etc/jupyter
    jupyterlab_git enabled
    - Validating jupyterlab_git...
      jupyterlab_git 0.23.3 OK

Config dir: /usr/local/etc/jupyter
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.7 OK
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  OK

次にフロント側のextensionを確認します。


root@62ecd14f5e8a:/srv/jupyterhub# jupyter labextension list
JupyterLab v3.0.7
Other labextensions (built into JupyterLab)
   app dir: /usr/local/share/jupyter/lab
        @jupyterlab/git v0.23.3 enabled  X
        nbdime-jupyterlab v2.0.1 enabled  X

   The following extension are outdated:
        @jupyterlab/git
        nbdime-jupyterlab

   Consider running "jupyter labextension update --all" to check for updates.

Git extensionがoutdatedになっているため、アップデートします。


root@62ecd14f5e8a:/srv/jupyterhub# jupyter labextension update --all
An error occured.
ValueError: Please install nodejs >=12.0.0 before continuing. nodejs may be installed using conda or directly from the nodejs website.
See the log file for details:  /tmp/jupyterlab-debug-n1cjjsd7.log

ここで、エラー発生。nodejsのバージョンを上げよとのことです。こちらを参考にして、nodejsを12にバージョンアップします。


curl -fsSL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

その後extensionのバージョンを上げます。

root@62ecd14f5e8a:/srv/jupyterhub# jupyter labextension update --all
Updating nbdime-jupyterlab to version 2.1.0-beta.1
Updating @jupyterlab/git to version 0.30.0-beta.2
Building jupyterlab assets (production, minimized)

改めてフロント側のextensionを確認します。

root@62ecd14f5e8a:/srv/jupyterhub# jupyter labextension list
JupyterLab v3.0.7
Other labextensions (built into JupyterLab)
   app dir: /usr/local/share/jupyter/lab
        @jupyterlab/git v0.30.0-beta.2 enabled OK
        nbdime-jupyterlab v2.1.0-beta.1 enabled OK

Jupyterlab-gitが0.23.3から0.30.0-beta.2にアップデートされました。
リリース情報を見ると、0.30.0b1でJupyterlab version3に対応になったようです。ただ、2021年2月18日時点でpip install でバージョンを指定しなければ0.23.3がインストールされてしまうため、Outdatedになってしまうようです。

次にサーバ側のバージョンも上げておきます。


root@62ecd14f5e8a:/srv/jupyterhub# pip3 install jupyterlab-git==0.30.0b2
root@62ecd14f5e8a:/srv/jupyterhub# jupyter server extension list
Config dir: /root/.jupyter

Config dir: /usr/etc/jupyter
    jupyterlab_git enabled
    - Validating jupyterlab_git...
      jupyterlab_git 0.30.0b2 OK

Config dir: /usr/local/etc/jupyter
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.7 OK
    jupyterlab_git enabled
    - Validating jupyterlab_git...
      jupyterlab_git 0.30.0b2 OK
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  OK
    nbdime enabled
    - Validating nbdime...
      nbdime 3.0.0.b1 OK

Jupyterhubを起動します。

jupyterhub jupyterhub_config.py 

Gitのボタンが表示され、うまくいきました。

Jupyterlab 2.2.9 の場合

Git extensionの方はまだbeta版ということもあるので、stable releaseである0.23.3を使ってみようと思い、対応しているJupyterlab 2系のものを試してみます。Jupyterhubも1つ前のバージョンである1.2系で最新のものを試しました。
Dockerのページによると1.2.2が最後のバージョンになっていたので、これを使ってみます。
また、Jupyterlabは同じ時期にリリースされている、2.2.9を使ってみます(詳細は公式ドキュメント参照)。

以下、同様に起動&設定していきます。

docker run -it -p 8000:8000 --name jupyterhub122 jupyterhub/jupyterhub:1.2.2 bash
apt update
apt install python3 python3-pip npm nodejs libnode64 vim git
npm install -g configurable-http-proxy
pip3 install -U pip
pip3 install jupyterlab==2.2.9
pip3 install jupyterlab-git==0.23.3
jupyterhub --generate-config
vim jupyterhub_config.py 
jupyterhub_config
c.Spawner.default_url = '/lab'
c.Spawner.notebook_dir = '~/notebook'
c.Authenticator.admin_users = {'testadmin'}
c.Authenticator.allowed_users = {'testuser01'}
adduser testadmin
mkdir -p -m 777 /home/testadmin/notebook
chown testadmin: /home/testadmin/notebook
adduser testuser01
mkdir -p -m 777 /home/testuser01/notebook
chown testuser01: /home/testuser01/notebook

Jupyterlab 2系では起動の前にビルドします。


jupyter lab build

ビルドが終わったらJupyterhubを起動します。


jupyterhub jupyterhub_config.py 

こちらはすんなりextensionを入れられました。

まとめ

  • Jupyterlab 3.0.7の場合
    • フロント&サーバともにJupyterlab-gitは0.30.02b(以上)を指定(0.30.01bは試しましたが動かなかったです)
    • nodejsを12以上にアップデートする必要あり
  • Jupyterlab 2.2.9の場合
    • Jupyterlab-gitは0.23.3でOK
    • 起動前にビルドする必要あり

参考にした記事など