JupyterLab にJavaScript(node.js)kernel追加(ijavascript)について

April 19, 2024 – 4:34 pm

JupyterLabにおいてJavascript(node.js)kernelの追加に必要なijsinstallのnpm install手続きで不安定な症状があらわれた。

何とか解決できたので、以下、メモしておいた。

JupyterLabの仮想環境上(jupyter_lab)でijavascriptをnpm installしたところ次のようなエラーが発生し、先に進めなくなった:

(jupyter_lab) [newana@Server02 ~]$ npm install -g ijavascript
  npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  
  Older versions may use Math.random() in certain circumstances, which is
   known to be problematic.  See https://v8.dev/blog/math-random for details.

    added 8 packages in 3s

この症状、以前にも遭遇したことがあったが、npmのかわりにyarnを使ってinstallすることが可能との話を見かけたので、試してみた。

まず、yarnのインストール:

(jupyter_lab) [anacon@Server02 ~]$ npm install -g yarn

added 1 package in 912ms

そして ijavascriptをinstall:

(jupyter_lab) [anacon@Server02 ~]$ yarn add ijavascript
yarn add v1.22.22
info No lockfile found.
[1/4] Resolving packages...
warning ijavascript > jp-kernel > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning ijavascript > jp-kernel > jmp > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 7 new dependencies.
info Direct dependencies
└─ ijavascript@5.2.1
info All dependencies
├─ ijavascript@5.2.1
├─ jmp@2.0.0
├─ jp-kernel@2.0.0
├─ nan@2.17.0
├─ nel@1.3.0
├─ node-gyp-build@4.8.0
└─ zeromq@5.3.1
Done in 2.54s.

~/node_modules/.bin配下をみると以下:

(jupyter_lab) [anacon@Server02 ~]$ ls -l
lrwxrwxrwx 1 anacon anacon 33 Apr 18 10:59 ijs -> ../ijavascript/bin/ijavascript.js
lrwxrwxrwx 1 anacon anacon 32 Apr 18 10:59 ijsconsole -> ../ijavascript/bin/ijsconsole.js
lrwxrwxrwx 1 anacon anacon 32 Apr 18 10:59 ijsinstall -> ../ijavascript/bin/ijsinstall.js
lrwxrwxrwx 1 anacon anacon 28 Apr 18 10:59 ijskernel -> ../ijavascript/lib/kernel.js
lrwxrwxrwx 1 anacon anacon 33 Apr 18 10:59 ijsnotebook -> ../ijavascript/bin/ijsnotebook.js
lrwxrwxrwx 1 anacon anacon 24 Apr 18 10:59 node-gyp-build -> ../node-gyp-build/bin.js
lrwxrwxrwx 1 anacon anacon 29 Apr 18 10:59 node-gyp-build-optional -> ../node-gyp-build/optional.js
lrwxrwxrwx 1 anacon anacon 31 Apr 18 10:59 node-gyp-build-test -> ../node-gyp-build/build-test.js
lrwxrwxrwx 1 anacon anacon 16 Apr 18 10:59 uuid -> ../uuid/bin/uuid

ijsinstallをnpx経由で実行:

(jupyter_lab) [anacon@Server02 ~]$ npx ijsinstall

ここで、kernel一覧でjavascriptのkernelができていることを確認:

(jupyter_lab) [anacon@Server02 ~]$ jupyter kernelspec list
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Available kernels:
  python3       /home/anacon/anaconda3/envs/jupyter_lab/share/jupyter/kernels/python3
  javascript    /home/anacon/.local/share/jupyter/kernels/javascript
  julia-1.10    /home/anacon/.local/share/jupyter/kernels/julia-1.10

以下、Lancherの出来上がり:


Post a Comment