一、说明
本文记录在ubuntu 24.04服务器上,通过 miniconda独立虚拟环境手动安装compyui的完整步骤。
适合有 NVIDIA 显卡的 AI 生图 / 视频生成服务器
二、显卡驱动安装
一、comfyui实现漫剧工作流,安装Ubuntu 22.04并安装Nvidia 驱动_ubuntu 26.04.1-CSDN博客文章浏览阅读232次,点赞5次,收藏5次。本文介绍了在Ubuntu系统下安装NVIDIA显卡驱动的完整流程。硬件配置为Intel Xeon E5645处理器和NVIDIA P104-100显卡。首先通过lshw命令确认显卡状态,然后禁用开源驱动nouveau。接着使用ubuntu-drivers查找可用驱动版本,选择推荐版本nvidia-driver-580进行安装。安装完成后重启系统,并通过nvidia-smi命令验证驱动安装成功。整个过程涵盖了驱动安装前准备、驱动选择、安装及验证等关键步骤。_ubuntu 26.04.1https://blog.csdn.net/jiangkp/article/details/163304168?spm=1001.2014.3001.5501
三、安装系统依赖
更新,每次安装系统都干干下面几条,都忘记了为什么这么做
sudo apt update
sudo apt upgrade -y
sudo apt autoremove
ComfyUI 是一个基于节点流程式的stable diffusion AI 绘图工具WebUI, 你可以把它想象成集成了stable diffusion功能的substance designer, 通过将stable diffusion的流程拆分成节点,实现了更加精准的工作流定制和完善的可复现性
四、安装Miniconda
#下载
wget -c https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
#安装
bash Miniconda3-latest-Linux-x86_64.sh
#初始化
source ~/.bashrc
#检验
conda --version
五、创建虚拟环境
#添加清华镜像
#清楚旧设置
conda config --remove-key channels
添加国内镜像通道(按优先级顺序)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
#优化关键参数:conda config --set show_channel_urls yes
conda config --set channel_priority flexible
#清除缓存并验证conda clean -i
conda config --show channels
#创建环境
conda create -n comfyui python=3.12
#激活环境
conda activate comfyui
#升级python工具,也可不进行
python -m pip install -U pip wheel setuptools
配置清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
六、安装pytorch
直接安装pip 版 PyTorch CUDA 12.6:周末很快
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
测试
python -c "import torch; print(torch.__version__)"
python -c "import torch; print(torch.version.cuda)"
python -c "import torch; print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CUDA is not available')"
七、下载 ComfyUI
cd ~
git clone https://github.com/comfyanonymous/ComfyUI.git
https://gitee.com/lightmusiclxy1/ComfyUI.git不行用下面这个
git clone https://gitee.com/lightmusiclxy1/ComfyUI.git
cd ~/ComfyUI
pip install -r requirements.txt
八、安装 ComfyUI Manager
cd ~/ComfyUI
pip install -r manager_requirements.txt
九、启动 ComfyUI
cd ~/ComfyUI
conda activate comfyui
python main.py --listen 0.0.0.0 --port 8188 --enable-manager
浏览器访问
http://192.168.1.3:8188
十、启动参数说明
--listen 0.0.0.0
允许局域网和外围访问
--port 8188
指定web端口
--enable-manager
启用ComfyUI Manager
十一、其他命令
conda remove --name comfyui --all
conda env remove -n comfyui
cd ~/ComfyUI
conda activate comfyui
CUDA_VISIBLE_DEVICES=0,1 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True python main.py --listen 0.0.0.0 --port 8188 --enable-manager --reserve-vram 1
指定 GPU 设备
CUDA_VISIBLE_DEVICES=0,1表示程序将可见并使用系统中的第 0 号和第 1 号 GPU。在代码中,PyTorch 会识别到这两个设备,并将它们映射为cuda:0和cuda:1,常用于多卡并行训练或推理 。优化显存分配
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True启用 PyTorch 的动态显存段扩展功能。该设置能有效减少显存碎片化,允许内存段在需要时动态扩展,从而提升显存利用率,特别适用于变长输入或频繁内存分配的场景,有助于避免CUDA out of memory错误
十二、电脑配置
终于出来了,是电脑配置的问题,以前的x58主板,支持的所有cpu都不支持avx2,所以换了主板,又换了cpu,现在cpu也很低端,i3 4160 2核4线程,够用,配置了16g内存,500g 固态硬盘,
看看我的配置:
主板 is8xm,支持1150针芯片,40元
cpu:要求不高,自己看着办,i3 4160 20元
内存:4根4g, 100元
ssd:京造3系480g,不好用,在windows 下有时候很慢,听说这盘有问题,但是在ubuntu系统没感觉,以前160,现在399,一般都有硬盘,先用着
电源500w以上,45元
然后就是两张p104显卡,听说容易坏,现在用了一张,还有一张,在路上,主板支持两张显卡,
支持的方式时能用算力,不能显示,正和我意,100元一张
所以这样的一个系统40+20+100+45+200=405元,不算固态硬盘