如果pip安装有错,比如pip install tokenizers,可以
# 1. 先安装 Rust(如果还没安装)
pkg install rust
# 2. 设置 Android API 级别(Termux 通常使用 API 24+)
export ANDROID_API_LEVEL=24
# 3. 重新安装
pip install tokenizers
也可以使用预编译的 wheel
# 更新包列表
pkg update
pkg search numpy
Checking availability of current mirror:
[*] https://mirrors.hust.edu.cn/termux/apt/termux-main: ok
Sorting... Done
Full Text Search... Done
python-numpy/stable,now 2.4.3 aarch64 [installed,automatic]
The fundamental package for scientific computing with Python
python-numpy-static/stable 2.4.3 aarch64
Static libraries for python-numpy
# 安装 numpy
pkg install python-numpy
再比如,psutil 在 Termux (Android) 上安装时遇到的平台兼容性问题。psutil 明确不支持 Android 平台。
# Termux 仓库中有 psutil 的预编译包
pkg install python-psutil
# 安装缺失的头文件
pkg install libandroid-spawn
# 设置环境变量
export CFLAGS="-I/data/data/com.termux/files/usr/include/android"
# 重新尝试安装
pip install ml_dtypes