本教程教你如何在 Termux 上安装 Matplotlib,无需等待编译,直接使用预编译的 wheel 包。
$ pip install matplotlib
Collecting matplotlib
Downloading matplotlib-3.10.8.tar.gz (53.2 MB)
Installing build dependencies ...
⚠️ 需要编译许多依赖(freetype, qhull, 等),在手机上几乎不可能完成
结果:编译依赖太多,内存不足经常失败 ❌
$ pip install --index-url https://nsyhykui.github.io/python_wheels_for_termux/simple/ matplotlib
Looking in indexes: https://nsyhykui.github.io/.../simple/
Collecting matplotlib
Downloading matplotlib-3.10.8-cp313-cp313-android_24_arm64_v8a.whl (10.2 MB)
Downloading numpy-2.4.4-cp313-cp313-android_24_arm64_v8a.whl (5.7 MB)
Successfully installed matplotlib-3.10.8 numpy-2.4.4 ...
real 2m15.789s
结果:2 分钟装好 ✅
pip config set global.index-url https://nsyhykui.github.io/python_wheels_for_termux/simple/
设置后,直接 pip install matplotlib 即可。
pip install --index-url https://nsyhykui.github.io/python_wheels_for_termux/simple/ matplotlib
tkinter 或 qt 相关错误:
import matplotlib
matplotlib.use('Agg') # 切换到无图形界面后端
import matplotlib.pyplot as plt
或者,如果你已经安装了 Termux:X11 或 VNC,可以正常使用默认后端。
python -c "import matplotlib; print(matplotlib.__version__)"
python -c "
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1,2,3], [4,5,6])
plt.savefig('test.png')
print('绘图成功,保存为 test.png')
"
libopenblas.so not found:运行 pkg install libopenblaslibc++_shared.so 相关错误:运行 pkg install libc++matplotlib.use('Agg') 即可解决🔗 ← 安装 NumPy | 安装 Pandas | 安装 SciPy | 安装 Jupyter | 返回教程首页 | 包索引