Jupyter 支援不同的 Kernel,此處記錄如何於 Termux 上安裝 javascript kernel。
(Kernel 可理解為 programming language)
安裝流程:
[1] Nodejs
apt install nodejs
$ node --version v14.2.0 $ npm --version 6.14.4 |
[2] ijavascript
npm -g install ijavascript (勿直接安裝,會出現 zmq 相關問題)
使用 npm 直接安裝 ijavascript 或 zeromp 都會產生編譯問題而失敗,需用 --zmq-external 選項來使用原先透過 apt install libzmq(4.3.2-2)安裝好的 libzmq 以避免編譯問題。另外,-g 選項也是必要的:
npm -g install ijavascript --zmq-external
$ npm -g install ijavascript --zmq-external /data/data/com.termux/files/usr/bin/ijs -> /data/data/com.termux/files/usr/lib/node_modules/ijavascript/bin/ijavascript.js /data/data/com.termux/files/usr/bin/ijsinstall -> /data/data/com.termux/files/usr/lib/node_modules/ijavascript/bin/ijsinstall.js /data/data/com.termux/files/usr/bin/ijskernel -> /data/data/com.termux/files/usr/lib/node_modules/ijavascript/lib/kernel.js /data/data/com.termux/files/usr/bin/ijsnotebook -> /data/data/com.termux/files/usr/lib/node_modules/ijavascript/bin/ijsnotebook.js /data/data/com.termux/files/usr/bin/ijsconsole -> /data/data/com.termux/files/usr/lib/node_modules/ijavascript/bin/ijsconsole.js > zeromq@5.2.0 install /data/data/com.termux/files/usr/lib/node_modules/ijavascript/node_modules/zeromq > node scripts/prebuild-install.js || (node scripts/preinstall.js && node-gyp rebuild) Requested to use external libzmq. Skipping download of prebuilt binaries. Requested to use external libzmq. Skipping libzmq build make: Entering directory '/data/data/com.termux/files/usr/lib/node_modules/ijavascript/node_modules/zeromq/build' CXX(target) Release/obj.target/zmq/binding.o ../binding.cc:399:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(this->handle(), callback_v.As<Function>(), 0, NULL); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ ../binding.cc:407:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(this->handle(), callback_v.As<Function>(), 0, NULL); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ ../binding.cc:458:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(this->handle(), callback_v.As<Function>(), 4, argv); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ ../binding.cc:473:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(this->handle(), callback_v.As<Function>(), 1, argv); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ ../binding.cc:814:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, 1, argv); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ ../binding.cc:893:10: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations] Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, 1, argv); ^ ../../nan/nan.h:1026:3: note: 'MakeCallback' has been explicitly marked deprecated here NAN_DEPRECATED inline v8::Local<v8::Value> MakeCallback( ^ ../../nan/nan.h:106:40: note: expanded from macro 'NAN_DEPRECATED' # define NAN_DEPRECATED __attribute__((deprecated)) ^ 6 warnings generated. SOLINK_MODULE(target) Release/obj.target/zmq.node COPY Release/zmq.node make: Leaving directory '/data/data/com.termux/files/usr/lib/node_modules/ijavascript/node_modules/zeromq/build' + ijavascript@5.2.0 added 67 packages from 65 contributors in 16.939s |
安裝後位於 /data/data/com.termux/files/usr/lib/node_modules
[3] ijsinstall
直接執行 ijsinstall 進行安裝
[4] 執行
<1> 登入 jupyter lab 後即可看到 javascript (Node.js) 選項(若已登入按重新整理瀏覽器即會出現)
<2> 在 ipynb 中測試 javascript 程式碼
Troubleshooting:
[1] 若執行 npm -g install ijavascript(沒有 --zmq-external 選項時),會出現安裝錯誤:
configure: error: None of '' are valid pollers on this platform child process exited with code 1 |
需透過下面指令反安裝:
npm uninstall ijavascript
[2] 若執行 npm install ijavascript --zmq-external(沒有 -g 選項時):
會安裝於 home/node_modules 下,導致系統先取用 home/node_modules/ijavascript,後續執行 ijsinstall 會有錯誤:
$ ijsinstall ….. [I 13:24:58.314 LabApp] KernelRestarter: restarting kernel (4/5), new random ports internal/modules/cjs/loader.js:1226 return process.dlopen(module, path.toNamespacedPath(filename)); ^ Error: dlopen failed: cannot locate symbol "zmq_msg_init" referenced by |
若曾使用沒有 -g 選項的 npm install ijavascript 或 npm install ijavascript --zmq-external,需先移除:
npm uninstall ijavascript
參考:
https://github.com/n-riesco/ijavascript
https://www.npmjs.com/package/ijavascript
https://github.com/zeromq/zeromq.js/
沒有留言:
張貼留言