AI

Mac安装启动ComfyUI 的详细教程

ComfyUI 是一个模块化的 Stable Diffusion GUI,工作界面是可视化的流程节点式。

相对于 Stable Diffusion WebUI 生成图像更加直观易控制,但是也会更复杂,门槛更高,新手还是建议先部署 Stable Diffusion WebUI 后,将 SD 的工作流程熟悉起来再使用 ComfyUI。

安装步骤


前提条件

  • Mac computers with Apple silicon or AMD GPUs
  • macOS 12.3 or later
  • Python 3.7 or later
  • Xcode command-line tools: xcode-select --install

1. 下载ComfyUI的代码

git clone https://github.com/comfyanonymous/ComfyUI.git

2.切换到ComfyUI工程路径,创建python虚拟环境

cd ComfyUI
python3.10 -m venv venv-comfyui

3.激活python环境

source venv-comfyui/bin/activate

4.安装mac PyTorch with MPS support

参考:https://developer.apple.com/metal/pytorch

pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

5.测试mps是否安装成功

创建一个python文件test.py,内容如下:

import torch
if torch.backends.mps.is_available():
    mps_device = torch.device("mps")
    x = torch.ones(1, device=mps_device)
    print (x)
else:
    print ("MPS device not found.")

执行该文件,看输出结果

python test.py

如果输出如下,则安装成功

tensor([1.], device='mps:0')

6.安装ComfyUI依赖

要进入 ComfyUI 目录,然后再用代码 pip install -r requirements.txt 来安装 Dependencies。

pip install -r requirements.txt

7.启动ComfyUI画面

python main.py
(venv-comfyui) xxx@xxxMac-mini ComfyUI % python main.py
Checkpoint files will always be loaded safely.
Total VRAM 24576 MB, total RAM 24576 MB
pytorch version: 2.7.0.dev20250220
Set vram state to: SHARED
Device: mps
Using sub quadratic optimization for attention, if you have memory or speed issues try using: --use-split-cross-attention
ComfyUI version: 0.3.14
****** User settings have been changed to be stored on the server instead of browser storage. ******
****** For multi-user setups add the --multi-user CLI argument to enable multiple user profiles. ******
[Prompt Server] web root: /Users/xxxx/Documents/ComfyUI/ComfyUI/web

Import times for custom nodes:
0.0 seconds: /Users/xxx/Documents/ComfyUI/ComfyUI/custom_nodes/websocket_image_save.py

Starting server

To see the GUI go to: http://127.0.0.1:8188

启动后可以看到 Stable Diffusion GUI 的界面类似一个思维导图的节点工作流程界面,需要注意的是在使用过程中不要关闭终端。