TOP

2020年9月20日 星期日

[Jupyter] Install JupyterLab on Termux


 

 

[Installation]

[1] 安裝 ipython

pip install ipython

因有警告,可以執行:pip install --upgrade pip 來更新一下 pip

 

測試 ipython

$ ipython

Python 3.8.3 (default, May 14 2020, 14:40:29)

Type 'copyright', 'credits' or 'license' for more information

IPython 7.14.0 -- An enhanced Interactive Python. Type '?' for help.

 

In [1]: import math

 

[2-1] 安裝 jupyterlab (fail)

pip install jupyterlab

 

上面指令執行後發生錯誤的地方:

<1>

error: command 'aarch64-linux-android-clang++' failed with exit status 1

<2>

    aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -fPIC -I/usr/local/include -Izmq/utils -c build/temp.linux-aarch64-3.8/scratch/vers.c -o build/temp.linux-aarch64-3.8/scratch/vers.o

    build/temp.linux-aarch64-3.8/scratch/vers.c:4:10: fatal error: 'zmq.h' file not found

=> 修正 zmq 錯誤:

apt install libcrypt-dev    <<< Fail >>>

$ apt install libcrypt-dev

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package libcrypt-dev is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or

is only available from another source

However the following packages replace it:

  libcrypt

 

E: Package 'libcrypt-dev' has no installation candidate

 

apt install libzmq    <<< Success >>>

$ apt install libzmq

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

  libandroid-spawn liblzo lzip lzop ninja

Use 'apt autoremove' to remove them.

The following additional packages will be installed:

  libsodium

The following NEW packages will be installed:

  libsodium libzmq

0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.

Need to get 392 kB of archives.

After this operation, 1516 kB of additional disk space will be used.

Do you want to continue? [Y/n]

Get:1 https://dl.bintray.com/termux/termux-packages-24 stable/main aarch64 libsodium aarch64 1.0.18-1 [98.7 kB]

Get:2 https://dl.bintray.com/termux/termux-packages-24 stable/main aarch64 libzmq aarch64 4.3.2-2 [294 kB]

Fetched 392 kB in 3s (121 kB/s)

Selecting previously unselected package libsodium.

(Reading database ... 24460 files and directories currently installed.)

Preparing to unpack .../libsodium_1.0.18-1_aarch64.deb ...

Unpacking libsodium (1.0.18-1) ...

Selecting previously unselected package libzmq.

Preparing to unpack .../libzmq_4.3.2-2_aarch64.deb ...

Unpacking libzmq (4.3.2-2) ...

Setting up libsodium (1.0.18-1) ...

Setting up libzmq (4.3.2-2) ...

Processing triggers for man (1.14.5-1) ...

 

[2-2] 再次安裝 jupyterlab (success)

pip install jupyterlab

 

 

[Run]

jupyter lab or jupyter notebook

$ jupyter lab

[I 17:27:46.866 LabApp] Writing notebook server cookie secret to /data/data/com.termux/files/home/.local/share/jupyter/runtime/notebook_cookie_secret

[I 17:28:00.967 LabApp] JupyterLab extension loaded from /data/data/com.termux/files/usr/lib/python3.8/site-packages/jupyterlab

[I 17:28:00.969 LabApp] JupyterLab application directory is /data/data/com.termux/files/usr/share/jupyter/lab

[I 17:28:00.995 LabApp] Serving notebooks from local directory: /data/data/com.termux/files/home/code

[I 17:28:00.996 LabApp] The Jupyter Notebook is running at:

[I 17:28:00.996 LabApp] http://localhost:8888/?token=b63ed1537a68a100231ef97041c2f8b4891724acad0a3668

[I 17:28:00.997 LabApp]  or http://127.0.0.1:8888/?token=b63ed1537a68a100231ef97041c2f8b4891724acad0a3668

[I 17:28:00.997 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[W 17:28:01.020 LabApp] No web browser found: could not locate runnable browser.

[C 17:28:01.021 LabApp]

 

    To access the notebook, open this file in a browser:

        file:///data/data/com.termux/files/home/.local/share/jupyter/runtime/nbserver-11420-open.html

    Or copy and paste one of these URLs:

        http://localhost:8888/?token=b63ed1537a68a100231ef97041c2f8b4891724acad0a3668

     or http://127.0.0.1:8888/?token=b63ed1537a68a100231ef97041c2f8b4891724acad0a3668

 

Termux 下執行 jupyter lab:

 

使用 localhost 登入 jupyter lab:

 

 

[Remote access]

[1] 執行 jupyter notebook --generate-config 產生 config file: jupyter_notebook_config.py

[2] 執行 jupyter notebook password 設定登入密碼後產生 jupyter_notebook_config.json

[3] 修改 jupyter_notebook_config.json,限定登入 IP

$ cd .jupyter/

$ pwd

/data/data/com.termux/files/home/.jupyter

$ ls

lab  migrated

 

$ jupyter notebook --generate-config

Writing default config to:

/data/data/com.termux/files/home/.jupyter/jupyter_notebook_config.py

 

$ jupyter notebook password

Enter password:

Verify password:

[NotebookPasswordApp] Wrote hashed password to /data/data/com.termux/files/home/.jupyter/jupyter_notebook_config.json

 

=> server 允許所有 IP 登入:

修改 jupyter_notebook_config.json (可先備份原檔):

{

  "NotebookApp": {

    "ip": "*",

    "open_browser": false

  }

}

注意:

如用瀏覽器無法連上 LAN 中的 jupyter, 請檢查是否啟用了 VPN

(需關閉 VPN 才可順利連上)

 

 

[啟用 Jupyter Lab]

jupyter lab --port 8888 --no-browser

$ jupyter lab --port 8888 --no-browser

[W 13:11:53.784 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.

[I 13:12:48.715 LabApp] JupyterLab extension loaded from /data/data/com.termux/files/usr/lib/python3.8/site-packages/jupyterlab

[I 13:12:48.717 LabApp] JupyterLab application directory is /data/data/com.termux/files/usr/share/jupyter/lab

[I 13:12:48.747 LabApp] Serving notebooks from local directory: /data/data/com.termux/files/home/.jupyter

[I 13:12:48.747 LabApp] The Jupyter Notebook is running at:

[I 13:12:48.748 LabApp] http://localhost:8888/

[I 13:12:48.748 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[I 13:12:48.813 LabApp] 302 GET / (192.168.1.101) 4.11ms

[I 13:12:48.868 LabApp] 302 GET /lab? (192.168.1.101) 3.38ms

或直接啟用 (預設為 port 8888):

jupyter lab

$ jupyter lab

[W 16:27:52.991 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.

[I 16:27:54.193 LabApp] JupyterLab extension loaded from /data/data/com.termux/files/usr/lib/python3.8/site-packages/jupyterlab

[I 16:27:54.195 LabApp] JupyterLab application directory is /data/data/com.termux/files/usr/share/jupyter/lab

[I 16:27:54.227 LabApp] Serving notebooks from local directory: /data/data/com.termux/files/home

[I 16:27:54.229 LabApp] The Jupyter Notebook is running at:

[I 16:27:54.229 LabApp] http://localhost:8888/

[I 16:27:54.230 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[I 16:28:09.922 LabApp] Build is up to date

[I 16:28:11.702 LabApp] Kernel started: ab753168-28ca-4a28-9eee-7dc5fa77cf76

[I 16:28:12.210 LabApp] Adapting from protocol version 5.1 (kernel ab753168-28ca-4a28-9eee-7dc5fa77cf76) to 5.3 (client).

[I 16:28:12.281 LabApp] Adapting from protocol version 5.1 (kernel ab753168-28ca-4a28-9eee-7dc5fa77cf76) to 5.3 (client).

[I 16:30:11.469 LabApp] Saving file at /Untitled.ipynb

 

 

[遠端登入 server]

http://192.168.1.104:8888/lab

 

 

 

若要使用 Notebook 介面, 將網址後的 /lab 改為 /tree 即可:

http://192.168.1.104:8888/tree

 

[停止 Jupyter Lab]

Termux 下按 Ctrl-C 後會有詢問指令, 選擇 y 終此 notebook server:

Shutdown this notebook server (y/[n])? y

[C 16:41:32.043 LabApp] Shutdown confirmed

[I 16:41:32.048 LabApp] Shutting down 1 kernel

[I 16:41:37.177 LabApp] Kernel shutdown: ab753168-28ca-4a28-9eee-7dc5fa77cf76

 

 

參考:

在本地使用远程 Jupyter Lab 服务器

Setting up a Jupyter Lab remote server

把安卓手机性能发挥到极致之-Termux安装PythonJupyter



沒有留言:

張貼留言