Ubuntu24.04安装ComfyUi

216 阅读2分钟

前言:ubuntu 20.04 就别安装了,因为gcc等版本太低

开始安装:

机器配置及环境: Ubuntu 24.04.3 LTS CPU:Xeon(R) Gold 6254 mem:755G A100-40G * 4

新建conda环境

conda create -n comfyui python=3.11 -y
conda activate comfyui
1 自动安装
pip install comfy-cli
comfy install
2 手动安装

下载ComfyUi

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

安装PyTorch

# 示例命令,请务必核对官网命令
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt

安装ComfyUi-manager

cd custom_nodes/cd 
git clone https://github.com/ltdrdata/ComfyUI-Manager.git

启动服务

sudo ufw allow 9000/tcp
python main.py --cuda-device 0 --listen 0.0.0.0 --port 9000

访问IP:9000端口,出现界面就可以了。

后续步骤:

创建启动脚本(/etc/systemd/system/comfyui.service):

[Unit]
Description=ComfyUI - Stable Diffusion GUI
After=network.target
# 设置启动限制策略,防止无限重启
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Type=simple
User=pan
# 工作目录(根据你提供的信息)
WorkingDirectory=/home/pan/comfy/ComfyUI
# 核心启动命令:激活conda环境并启动ComfyUI(关键!)
ExecStart=/bin/bash -c "source /home/pan/anaconda3/etc/profile.d/conda.sh && conda activate comfyui && python main.py --listen 0.0.0.0 --port 9000"
Restart=on-failure
RestartSec=30
# 可选的实用环境变量:设置镜像、内存管理等
Environment="HF_ENDPOINT=https://hf-mirror.com"
Environment="PYTHONUNBUFFERED=1"
# 将日志输出到系统日志
StandardOutput=journal
StandardError=journal
SyslogIdentifier=comfyui

[Install]
WantedBy=multi-user.target

注:这里用户为pan 相应的环境配置文件:/home/pan/anaconda3/etc/profile.d/conda.sh

生效:

sudo systemctl daemon-reload
sudo systemctl enable comfyui
sudo systemctl start comfyui

其它:

设置conda国内源

conda config --add channels mirrors.tuna.tsinghua.edu.cn/anaconda/pk… conda config --add channels mirrors.tuna.tsinghua.edu.cn/anaconda/pk… conda config --add channels mirrors.tuna.tsinghua.edu.cn/anaconda/cl…

安装 cuda

conda install cudatoolkit-dev=12.1.0 -c nvidia

查看 torch版本

python -c "import torch; print(f'PyTorch版本: {torch.version}'); print(f'CUDA版本: {torch.version.cuda}')"

安装 torch

pip install --upgrade torch torchvision torchaudio -i pypi.tuna.tsinghua.edu.cn/simple/

安装缺失的model

pip install opencv-python numba librosa polygraphy -i pypi.tuna.tsinghua.edu.cn/simple/

安装 flash-attn

conda install -c conda-forge flash-attn

安装 sageattention

pip install sageattention==1.0.6

请仔细观察CLI输出情况,如的报错,请提交deepseek找到问题并修正

# 首先确保有编译环境
conda install -c conda-forge ninja
# 从源码安装 flash-attn
pip install flash-attn --no-build-isolation --no-cache-dir --verbose

解决不能访问huggingface.co问题

设置 HF_ENDPOINT 环境

export HF_ENDPOINT=https://hf-mirror.com