ComfyUI 本地部署
环境概述
- 操作系统:Ubuntu 22.04.5 LTS
- GPU:NVIDIA GeForce RTX 4090
- CUDA版本:12.6
- Python版本:3.10.18
部署步骤
1. 准备环境
检查系统环境
检查NVIDIA驱动和CUDA版本
nvidia-smi
# nvidia-smi
Wed Jul 23 00:58:00 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.28.03 Driver Version: 560.28.03 CUDA Version: 12.6 |
检查CUDA编译工具版本
nvcc --version
# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Fri_Jun_14_16:34:21_PDT_2024
Cuda compilation tools, release 12.6, V12.6.20
Build cuda_12.6.r12.6/compiler.34431801_0
检查Python版本
python --version
# python --version
Python 3.10.12
检查Git版本
git --version
# git --version
git version 2.34.1
创建Conda虚拟环境
# 创建名为comfyuienv的Python 3.10环境
conda create -n comfyuienv python=3.10
# 激活环境
conda activate comfyuienv
2. 安装PyTorch
安装与CUDA 12.6兼容的PyTorch 2.7.0版本:
pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/cu126
验证PyTorch安装:
python -c "import torch; print('PyTorch版本:', torch.__version__, '\nCUDA可用:', torch.cuda.is_available(), '\nCUDA版本:', torch.version.cuda if torch.cuda.is_available() else '不可用')"
3. 安装ComfyUI
克隆ComfyUI仓库
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
安装ComfyUI依赖
pip install -r requirements.txt
4. 安装自定义节点依赖
ComfyUI的自定义节点可能需要额外的依赖:
# 安装gitpython和gguf
pip install gitpython gguf
# 安装toml
pip install toml
# 安装uv
pip install uv
5. 启动ComfyUI
python main.py
常见问题及解决方案
自定义节点加载失败
如果遇到自定义节点加载失败,通常是因为缺少依赖。查看错误信息并安装相应的依赖:
- comfyui-manager:需要
gitpython
、toml
和uv
- ComfyUI-GGUF:需要
gguf
PyTorch与CUDA兼容性
确保安装的PyTorch版本与系统的CUDA版本兼容。可以在PyTorch官网查询兼容版本:
https://pytorch.org/get-started/previous-versions/
使用建议
- ComfyUI-Manager:可用于安装更多自定义节点和模型
- 模型下载:可以通过ComfyUI-Manager下载常用的AI模型
- 工作流程:通过Web界面创建和编辑工作流程
- 资源管理:根据GPU显存大小调整模型加载设置