2024年Termux环境下Jupyter与Maturin的安装避坑指南

发布时间:2026/7/13 6:59:35

2024年Termux环境下Jupyter与Maturin的安装避坑指南 1. Termux环境准备与基础配置在安卓设备上搭建Python开发环境Termux无疑是最佳选择。最近我在Redmi Note 11上实测安装Jupyter Notebook和Maturin时发现2024年的版本兼容性问题比往年更棘手。先说说我的设备环境Termux 0.119.0-beta1 Android 13这个组合现在用的人不少。换源是第一步也是最重要的一步国内用户不换源的话后续操作基本都会卡住。我试过清华、阿里、中科大三个镜像源实测清华源目前最稳定。执行以下命令时要注意每条sed命令都是完整的一行中间不要换行sed -i s^\(deb.*stable main\)$#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main $PREFIX/etc/apt/sources.list sed -i s^\(deb.*science stable\)$#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable $PREFIX/etc/apt/sources.list.d/science.list sed -i s^\(deb.*games stable\)$#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable $PREFIX/etc/apt/sources.list.d/game.list换源后建议先更新软件包这里有个坑不要直接用pkg upgrade最好先pkg update再pkg upgrade否则有时会遇到哈希校验失败。我习惯加个-y参数省去确认步骤pkg update -y pkg upgrade -y2. Rust环境与Maturin安装指南Maturin作为Python-Rust混合编程的关键工具安装过程最容易翻车。2024年最新版Termux中直接cargo install maturin十有八九会报错主要是llvm工具链的问题。经过五次失败尝试后我总结出这个可靠方案首先安装必备的编译工具链pkg install -y binutils-is-llvm clang make cmake然后关键来了——不要从crates.io安装直接从GitHub仓库安装特定版本cargo install --locked --git https://github.com/PyO3/maturin.git maturin这个方法的妙处在于跳过了有问题的版本依赖。我遇到过最典型的E0308编译错误就是版本不匹配导致的类型系统冲突。如果安装过程中看到类似could not compilesyn的错误试试先更新Rust工具链rustup update stable安装完成后用maturin --version检查目前稳定版是1.4.0。有个细节要注意Termux的Rust环境会占用约1.5GB存储空间如果手机存储紧张建议先清理缓存cargo cache -a3. Python环境配置技巧Python安装看似简单实则暗藏玄机。2024年Termux官方源默认安装的是Python 3.11但实测发现与最新版Jupyter存在兼容问题。我的建议是pkg install -y python安装后立即设置pip镜像源否则后续装包会慢到怀疑人生。推荐创建配置文件mkdir -p ~/.pip echo -e [global]\nindex-url https://pypi.tuna.tsinghua.edu.cn/simple\n[install]\ntrusted-host https://pypi.tuna.tsinghua.edu.cn ~/.pip/pip.conf重点来了不要急着装Jupyter先解决依赖冲突。最近rpds-py这个包经常出问题手动指定版本安装更稳妥pip install rpds-py0.10.6 --no-cache-dir如果遇到ERROR: Failed building wheel for XXX之类的错误大概率是缺少系统库。万能解决方案pkg install -y libffi openssl libzmq libcrypt4. Jupyter Notebook终极安装方案到了最关键的Jupyter安装环节2024年最大的坑是pyzmq版本问题。最新版26.2.0在Termux上根本无法正常绑定经过反复测试25.1.1版本最稳定pkg install -y libzmq pip install pyzmq25.1.1 --verbose安装过程如果卡在Building wheel for pyzmq可以加上环境变量加速编译export LDFLAGS-L/data/data/com.termux/files/usr/lib export CFLAGS-I/data/data/com.termux/files/usr/include正式安装Jupyter时建议分步进行先装ipython再装jupyterpip install ipython8.12.0 pip install jupyter1.1.1启动Jupyter有个小技巧用--no-browser参数可以避免不必要的错误提示jupyter notebook --no-browser --ip127.0.0.1看到输出中的http://localhost:8888/?tokenxxx就是成功了。在安卓浏览器中访问这个链接时如果出现连接拒绝试试把127.0.0.1换成实际局域网IP。我习惯用Termux的API启动浏览器termux-open-url http://localhost:8888最后提醒Jupyter在Termux上运行时记得保持Termux在前台不锁屏否则内核容易断开。可以用termux-wake-lock防止休眠termux-wake-lock termux-wake-unlock

相关新闻