最近在本地部署 LLaMA-Factory 时,遇到了一系列环境配置问题——从 GitHub 克隆失败、CUDA 不可用到虚拟环境依赖缺失,最终成功启动 WebUI。本文整理完整的排错过程和解决方案。
一、问题背景:本地部署 LLaMA-Factory 的核心诉求
目标是在 Windows 10 环境下,基于 Anaconda 创建虚拟环境,部署 LLaMA-Factory 并启动 WebUI,利用本地 NVIDIA MX230 显卡(2GB 显存)实现 GPU 加速。主要涉及三类问题:
- 仓库克隆失败(GitHub 连接重置、Gitee 403 权限拒绝);
- PyTorch CUDA 支持缺失(报'Torch not compiled with CUDA enabled');
- 虚拟环境依赖缺失(直接运行 WebUI 报'ModuleNotFoundError: No module named 'torch'')。
二、核心报错解析与分步解决方案
坑 1:仓库克隆失败——网络限制与镜像选择
报错现象
从 GitHub 克隆时提示连接重置,从某 Gitee 镜像克隆时提示 403 权限拒绝:
(base) PS E:\pc-project> git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
Cloning into 'LLaMA-Factory'...
fatal: unable to access 'https://github.com/hiyouga/LLaMA-Factory.git/': Recv failure: Connection was reset
原因分析
GitHub 克隆失败是国内网络访问限制导致;Gitee 403 是因为选择的镜像仓库权限设置问题(非公开可克隆)。
解决方案
优先选择 GitHub 国内镜像站,配合 Git 网络配置优化;备选方案使用官方维护的 Gitee 镜像:
# 1. 配置 Git 超时与网络参数(避免连接超时)
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
git config --global http.timeout 300
# 2. 使用 GitHub 镜像站克隆(推荐)
git clone --depth 1 https://github.91chi.fun/https://github.com/hiyouga/LLaMA-Factory.git
# 3. 备选:使用 Gitee 官方维护镜像
rm -rf LLaMA-Factory
git clone https://gitee.com/mirrors_LLaMA-Factory/LLaMA-Factory.git
如果 Git 命令仍失败,可直接手动下载源码压缩包:访问 https://github.com/hiyouga/LLaMA-Factory/archive/refs/heads/main.zip,解压后重命名为'LLaMA-Factory'即可。
坑 2:CUDA 不可用——PyTorch 版本错配
报错现象
进入 Python 交互环境,调用 torch.cuda 相关函数时报错:
>>> import torch
>>> torch.cuda.current_device()
Traceback (most recent call last):
File , line , <module>
File , line , _lazy_init
AssertionError()
AssertionError: Torch compiled CUDA enabled

