Windows 11 下 lora-scripts 安装排坑实录:从 Python 版本到依赖地狱
设备与环境:Windows 11 / Python 3.14.5(初版) / lora-scripts v1.10.0(git clone)
作为一个刚入坑 AI 绘画的新手,为了训练自己的第一个 LoRA 模型,我按照教程开始了 lora-scripts 的安装。本以为跟着 README 一步步来就能搞定,结果被各种报错硬控了整整一个晚上。这篇文章记录了我从 install-cn.ps1 到 run_gui.ps1 遇到的所有“惊喜”和解决办法。如果你也卡在类似的报错里,希望这篇能帮你省下几个小时。
1. Python 版本冲突:3.14.5 不被 PyTorch 支持
报错现象
执行 install-cn.ps1 时,在安装 PyTorch 环节报错:
ERROR: Could not find a version that satisfies the requirement torch==2.7.0+cu128
原因分析lora-scripts 指定的 PyTorch 2.7.0 最高只支持 Python 3.13,而我系统默认的 Python 3.14.5 超出了支持范围,导致 pip 找不到匹配的安装包。
解决办法
-
使用
pyenv-win安装并切换至 Python 3.11.9(推荐版本) -
删除项目下的
venv虚拟环境文件夹,重新运行install-cn.ps1,脚本会基于 Python 3.11 重建环境
# 安装 pyenv-win 后
pyenv install 3.11.9
pyenv global 3.11.9
2. 网络连接测试失败:Google 连通性检查超时
报错现象
每次启动都会出现:
ERROR Network test failed: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded
原因分析lora-scripts 启动时会尝试连接 www.google.com 作为网络连通性测试,国内环境访问 Google 会超时。这不是致命错误,脚本会自动切换至国内镜像源(清华、交大),不影响后续功能。
解决办法
直接忽略,或者启动时配置代理(如有需要)。
3. Protobuf 版本冲突:TensorBoard 与 onnxruntime 的战争
这是整个过程最折磨人的地方,集中表现为 多个包对 protobuf 版本要求完全相反:
| 包名 | 要求的 protobuf 版本 |
|---|---|
tensorboard 2.10.1 |
< 3.20(严格) |
open-clip-torch |
< 4 |
wandb |
< 5 |
onnxruntime >= 1.27.0 |
>= 4.25.8 |
报错现象(反复出现):
ERROR: pip's dependency resolver ... tensorboard 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 7.35.1 onnxruntime 1.27.0 requires protobuf>=4.25.8, but you have protobuf 3.19.6
原因分析lora-scripts 的启动逻辑会自动安装 onnxruntime 和 onnxruntime-gpu,这会导致 protobuf 被强制升级到 7.x,从而与 tensorboard 产生冲突,陷入“降级 → 启动脚本自动升级 → 再降级”的死循环。
解决办法(最终方案)
-
第一步:手动安装一个不强制升级 protobuf 的旧版 onnxruntime
-
第二步:锁定 protobuf 版本为 3.19.6
-
第三步:修改
gui.py或使用启动参数,阻止脚本自动安装 onnxruntime
# 安装旧版 onnxruntime(不升级 protobuf)
pip install onnxruntime==1.15.0 --no-deps --force-reinstall
# 锁定 protobuf 版本
pip install protobuf==3.19.6
4. 启动参数无效:--skip-prepare-onnxruntime 不生效
现象
即使加了 .\run_gui.ps1 --skip-prepare-onnxruntime,脚本依然执行了 installing onnxruntime。
原因gui.py 中虽然定义了 --skip-prepare-onnxruntime 参数,但 launch() 函数中缺少对应的条件判断逻辑,导致参数被忽略。
解决办法
我通过全局搜索onnxruntime,在mikazuki/launch_utils.py文件上找到了疑似安装onnxruntime 这个依赖的地方setup_onnxruntime函数,我将这个函数直接返回True
5. 最终成功方案
经过多轮排查,最终通过以下组合操作让 GUI 顺利跑起来:
| 步骤 | 操作 |
|---|---|
| ① | 使用 pyenv 将 Python 切换至 3.11.9 |
| ② | 删除 venv 文件夹,重建虚拟环境 |
| ③ | 安装 onnxruntime==1.15.0 --no-deps,并锁定 protobuf==3.19.6 |
| ④ | 修改 gui.py,注释掉 install_onnxruntime 相关代码 |
| ⑤ | 使用 .\run_gui.ps1 --disable-tensorboard 启动,绕过 TensorBoard 的 protobuf 冲突 |
最终成功看到:
Server started at http://127.0.0.1:28000 Uvicorn running on http://127.0.0.1:28000
总结与避坑建议
-
Python 版本一定要选对:3.10.x 或 3.11.x 是当前 AI 工具链最稳妥的选择,不要追新。
-
protobuf 版本是重灾区:遇到 TensorBoard 和 onnxruntime 冲突时,优先考虑卸载 onnxruntime 或锁定 protobuf 版本。
-
善用启动参数:
--disable-tensorboard和--skip-prepare-environment可以在环境不完美时强行启动 GUI。 -
多看日志,少看报错:
Network test failed这类错误往往是纸老虎,真正的拦路虎是依赖版本冲突。
如果你的环境和我类似,可以直接参考最终方案中的组合操作,大概率能一次成功。希望这篇记录能让你少走一些弯路!

浙公网安备 33010602011771号