TOP

2020年10月29日 星期四

[Python] Install Python AI Learning packages on Termux

Android 平台上 AI 套件的資源有多種可選用,在安裝前可先搜集資訊,比較之後再決定採用何種方案。

 

AI 套件替代方案:

APK

Aid Learning (Android APP)

雲端

Google Colab (Colaboratory)

雲端

CoCalc (Collaborative Calculation and Data Science)

https://cocalc.com/index.html

 

Termux + Python packages for AI Learning

 

使用雲端的缺點主要是程式碼需上傳,如果不介意程式碼可能會被架 server 的公司取用,那麼使用雲端來使用 JupyterLab 是最容易的,客戶端只要使用瀏覽器登入遠端 JupyterLab server 即可,不需安裝任何程式:Google Colab google 帳號就可使用;CoCalc 有無註冊皆可使用,但無註冊的使用者工作 session 無法保存;Aid Learning 則是安裝在 Android 裝置的應用程式,已封裝好各種 AI packages,也可很容易就使用。

 

Termux 平台上安裝 Python AI Learning packages 需自行輸入安裝指令(透過 pip)。

優點:

    ◎ 可自主決定要安裝的套件及版本
    ◎ 不需上網也可使用
    ◎ 程式碼儲存在 Android 內部記憶體,不需公開

缺點:

    ◎ 相對較麻煩
    ◎ 遇到問題需自行搜集資訊排除

 

我個人是採用 Termux 來安裝,主要是為了隨時可在手機上檢視程式碼或執行測試,在 LAN 的環境下也可以很容易的在別台裝置登入手機端的 JupyterLab 來使用。在 Linux 平台下安裝軟體時常遇到版本相依性的問題,雖然很惱人,不過網路上通常找的到解法。

 

這裡記錄在 Termux 平台上透過 pip 安裝 AI 相關套件的方法,主要有:

[1] Numpy
        pip install numpy

[2] Pandas
        pip install pandas

[3] Matplotlib
        apt install freetype libpng pkg-config
        pip install matplotlib

[4] Scipy
        curl -L https://its-pointless.github.io/setup-pointless-repo.sh | sh
        apt install scipy

 

注意:有的套件安裝時間很長,需耐心等待。

 

安裝後需更新套件的話,使用更新指令:

pip install --upgrade xxx

xxx 是要更新的套件名,同樣的,可能需修正相依性的問題)

 

 

安裝套件:

[1] Numpy

pip install numpy

$ pip install numpy

Collecting numpy

  Downloading numpy-1.18.4.zip (5.4 MB)

     |████████████████████████████████| 5.4 MB 55 kB/s

  Installing build dependencies ... done

  Getting requirements to build wheel ... done

    Preparing wheel metadata ... done

Building wheels for collected packages: numpy

  Building wheel for numpy (PEP 517) ... done

  Created wheel for numpy: filename=numpy-1.18.4-cp38-cp38-linux_aarch64.whl size=10833680 sha256=00833838894345f954db1484028ea10834ac8eeb61e201648818fe02f1d8228b

  Stored in directory: /data/data/com.termux/files/home/.cache/pip/wheels/bd/b0/b1/59b5614f0a18f0d0d40d4e3dd0ca28613b921245c973ea27d8

Successfully built numpy

Installing collected packages: numpy

Successfully installed numpy-1.18.4

 

[2] Pandas: Panel data + Data analysis

pip install pandas

$ pip install pandas

Collecting pandas

  Downloading pandas-1.0.3.tar.gz (5.0 MB)

     |████████████████████████████████| 5.0 MB 4.5 MB/s

  Installing build dependencies ... done

 

  Getting requirements to build wheel ... done

    Preparing wheel metadata ... done

Collecting pytz>=2017.2

  Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)

     |████████████████████████████████| 510 kB 1.4 MB/s

Requirement already satisfied: numpy>=1.13.3 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from pandas) (1.18.4)

Requirement already satisfied: python-dateutil>=2.6.1 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from pandas) (2.8.1)

Requirement already satisfied: six>=1.5 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from python-dateutil>=2.6.1->pandas) (1.14.0)

Building wheels for collected packages: pandas

  Building wheel for pandas (PEP 517) ... done

  Created wheel for pandas: filename=pandas-1.0.3-cp38-cp38-linux_aarch64.whl size=23684254 sha256=8e21af4a1779ad3a06c350479f41116961fdc5f7813394cec871a8525b074e4b

  Stored in directory: /data/data/com.termux/files/home/.cache/pip/wheels/23/d2/44/50574994cafe4e229e05bbcb34f212f3cf9eda2d6364fe1f08

Successfully built pandas

Installing collected packages: pytz, pandas

Successfully installed pandas-1.0.3 pytz-2020.1

 

[3] Matplotlib: matlab + plot

<1> apt install freetype libpng pkg-config

$ apt install freetype libpng pkg-config

Reading package lists... Done

Building dependency tree

Reading state information... Done

pkg-config is already the newest version (0.29.2).

pkg-config set to manually installed.

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 NEW packages will be installed:

  freetype libpng

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

Need to get 562 kB of archives.

After this operation, 2052 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 libpng aarch64 1.6.37-2 [189 kB]

Get:2 https://dl.bintray.com/termux/termux-packages-24 stable/main aarch64 freetype aarch64 2.10.2 [374 kB]

Fetched 562 kB in 3s (175 kB/s)

Selecting previously unselected package libpng.

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

Preparing to unpack .../libpng_1.6.37-2_aarch64.deb ...

Unpacking libpng (1.6.37-2) ...

Selecting previously unselected package freetype.

Preparing to unpack .../freetype_2.10.2_aarch64.deb ...

Unpacking freetype (2.10.2) ...

Setting up libpng (1.6.37-2) ...

Setting up freetype (2.10.2) ...

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

 

<2> pip install matplotlib

$ pip install matplotlib

Collecting matplotlib

  Downloading matplotlib-3.2.1.tar.gz (40.3 MB)

     |████████████████████████████████| 40.3 MB 3.5 kB/s

Collecting cycler>=0.10

  Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)

Collecting kiwisolver>=1.0.1

  Downloading kiwisolver-1.2.0.tar.gz (52 kB)

     |████████████████████████████████| 52 kB 262 kB/s

Requirement already satisfied: numpy>=1.11 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from matplotlib) (1.18.4)

Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from matplotlib) (2.4.7)

Requirement already satisfied: python-dateutil>=2.1 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from matplotlib) (2.8.1)

Requirement already satisfied: six in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from cycler>=0.10->matplotlib) (1.14.0)

Using legacy setup.py install for matplotlib, since package 'wheel' is not installed.

Using legacy setup.py install for kiwisolver, since package 'wheel' is not installed.

Installing collected packages: cycler, kiwisolver, matplotlib

    Running setup.py install for kiwisolver ... done

    Running setup.py install for matplotlib ... done

Successfully installed cycler-0.10.0 kiwisolver-1.2.0 matplotlib-3.2.1

 

[4] Scipy

<1> 直接安裝 scipy 會有 Preparing wheel metadata ... error 錯誤出現:

pip install scipy

=> libraries mkl_rt not openblas found

 

<2> piontless

這個問題可透過安裝 piontless 解決,參考:

https://github.com/termux/termux-packages/issues/1737

 

安裝 piontless

curl -L https://its-pointless.github.io/setup-pointless-repo.sh | sh

 

<3> 此時再安裝 scipy 即可成功

apt install scipy

 

 

 

 

 

沒有留言:

張貼留言