Windows 上解决 ComfyUI 兼容性问题的系统化步骤
一 基线环境与版本匹配
nvidia-smi(右上显示的 CUDA 为驱动支持上限)python -c "import torch;print('PyTorch:',torch.__version__,'CUDA可用:',torch.cuda.is_available(),'CUDA版本:',torch.version.cuda,'GPU:',torch.cuda.get_device_name(0))"torch.cuda.is_available() 为 False 或报 “Torch not compiled with CUDA enabled”,说明装了 CPU 版或 CUDA 不匹配,需重装对应 CUDA 版本的 PyTorch。二 常见报错与修复清单
1) 卸载 CPU 版:pip uninstall torch torchvision torchaudio -y
2) 安装带 CUDA 的版本(示例为 CUDA 11.8 + Python 3.12):
pip install torch==2.2.0+cu118 torchvision==0.17.0+cu118 torchaudio==2.2.0+cu118 --index-url https://download.pytorch.org/whl/cu1183) 再次用上面的 Python 校验命令确认 CUDA 可用=True。
说明 whl 与 Python 主次版本/架构不匹配(如 cp312 对应 Python 3.12,win_amd64 对应 64 位)。先 python --version 与 python -c "import platform;print(platform.architecture())" 确认,再下载匹配版本。
使用官方源的 HTTPS 直链 + 断点续传工具(如 IDM/迅雷)离线下载 whl,或临时换国内镜像;安装命令:pip install C:\path\torch-2.2.0+cu118-cp312-cp312-win_amd64.whl。
先 pip uninstall torchaudio torchvision -y,再安装与已装 PyTorch 主版本一致 的配套版本(如 torch 2.2.0 → torchvision 0.17.0、torchaudio 2.2.0)。
Windows 上这类含 C++/CUDA 扩展的库经常缺预编译轮子。优先:
三 插件与依赖冲突治理
1) 在 custom_nodes 下 git clone 插件源码;
2) 打开插件的 requirements.txt,将刚性版本如 numpy==1.21.0 改为 numpy>=1.21.0 或删除版本号,避免“牵一发而动全身”;
3) 安装依赖时加 --no-deps,只装清单里的包,防止 pip 为适配某个插件把基础包整体降级/升级;
4) 若报缺依赖,单独补装该缺失包(优先匹配 Python/CUDA 的 whl)。
pip freeze > requirements.txt 固定基线;git clean 或重装 requirements.txt,再按插件维度逐步恢复。四 显卡与显存相关稳定性优化
torch.backends.cuda.matmul.allow_tf32 = Truetorch.backends.cudnn.benchmark = Trueos.environ["CUDA_VISIBLE_DEVICES"] = "0"(多卡时选择显存更充裕的 GPU);五 替代方案与一键环境
nvidia-container-toolkit 并重启 Docker;docker run --rm --gpus all nvidia/cuda:12.2-base-ubuntu22.04 nvidia-smi 验证 GPU 直通;docker run -d --name comfyui -p 8188:8188 ghcr.io/comfyanonymous/comfyui:latest;%USERPROFILE%\.wslconfig 中设置:[wsl2] memory=8GB; swap=8GB; processors=6,保存后执行 wsl --shutdown 生效。--no-gpu;COMFYUI_LOW_MEM=1 降低内存占用。