DGX Spark部署ComfyUI(一键安装脚本)
视频链接https://www.bilibili.com/video/BV1tfN36cEr4/?vd_source5ba34935b7845cd15c65ef62c64ba82f仓库链接GitHub - LitchiCheng/DGX-Spark · GitHub快速开始使用uv进行python环境和依赖的安装#!/usr/bin/env bash set -euo pipefail # 在当前脚本所在目录创建 ComfyUI SCRIPT_DIR$(cd $(dirname $0) pwd) COMFYUI_DIR${COMFYUI_DIR:-$SCRIPT_DIR/ComfyUI} UV_PYTHON$COMFYUI_DIR/.venv TORCH_CUDA${TORCH_CUDA:-auto} # 国内镜像源 PIP_INDEX_URLhttps://pypi.tuna.tsinghua.edu.cn/simple GREEN\033[0;32m; NC\033[0m info() { echo -e ${GREEN}[INFO]${NC} $*; } detect_gpu() { command -v nvidia-smi /dev/null nvidia-smi --query-gpudriver_version --formatcsv,noheader 2/dev/null | grep -q . echo yes || echo no } install_deps() { if command -v apt-get /dev/null; then sudo apt-get update -qq sudo apt-get install -y git python3 curl wget build-essential 21 | tee /tmp/comfyui.log elif command -v dnf /dev/null || command -v yum /dev/null; then local mgrdnf ! command -v dnf /dev/null mgryum $mgr install -y git python3 curl wget gcc make 21 | tee /tmp/comfyui.log fi } install_uv() { info 检查 uv... if ! command -v uv /dev/null; then info 安装 uv (极速 Python 包管理器)... curl -LsSf https://astral.sh/uv/install.sh | sh export PATH$HOME/.local/bin:$PATH # 如果仍找不到尝试其他方式 if ! command -v uv /dev/null; then pip install uv 21 | tee /tmp/comfyui.log fi fi info uv 版本$(uv --version) } clone_comfyui() { if [[ -d $COMFYUI_DIR/.git ]]; then info 更新 ComfyUI... (cd $COMFYUI_DIR git pull) 21 | tee /tmp/comfyui.log else rm -rf $COMFYUI_DIR 2/dev/null || true info 克隆 ComfyUI... git clone https://github.com/comfyanonymous/ComfyUI.git $COMFYUI_DIR 21 | tee /tmp/comfyui.log fi } create_venv() { if [[ -d $UV_PYTHON ]]; then info 虚拟环境已存在: $UV_PYTHON return 0 fi info 创建 uv 虚拟环境... uv venv $UV_PYTHON --python python3 21 | tee /tmp/comfyui.log } install_torch() { local mode$TORCH_CUDA if [[ $mode cpu ]] || [[ $mode ! yes $(detect_gpu) ! yes ]]; then info 安装 CPU-only PyTorch... uv pip install torch torchvision torchaudio --python $UV_PYTHON/bin/python --index-url https://download.pytorch.org/whl/cpu 21 | tee /tmp/comfyui.log else info 安装 CUDA PyTorch (cu124)... uv pip install torch torchvision torchaudio --python $UV_PYTHON/bin/python --index-url https://download.pytorch.org/whl/cu124 21 | tee /tmp/comfyui.log fi $UV_PYTHON/bin/python -c import torch; print(PyTorch:, torch.__version__) 21 | tee /tmp/comfyui.log } install_deps_py() { info 安装 ComfyUI 依赖 (使用清华源)... cd $COMFYUI_DIR UV_INDEX_URL$PIP_INDEX_URL uv pip install -r requirements.txt --python $UV_PYTHON/bin/python 21 | tee /tmp/comfyui.log } create_config() { local config_file$COMFYUI_DIR/user/config.ini [[ -f $config_file ]] return 0 info 创建配置... mkdir -p $(dirname $config_file) cat $config_file EOF [Paths] user_directory$HOME/.config/ComfyUI models_configextra_model_paths.yaml.example [Server] port8188 listen0.0.0.0 enable-uploadstrue EOF } main() { info 安装目录$COMFYUI_DIR info Python 环境$UV_PYTHON (uv 管理) command -v git /dev/null || { echo 请先安装 git; exit 1; } install_deps install_uv clone_comfyui create_venv install_torch install_deps_py create_config info 部署完成! echo echo 启动方式: echo cd $COMFYUI_DIR echo uv run python main.py # 直接用 uv 运行 echo 或 echo . \$UV_PYTHON/bin/activate python main.py # 激活虚拟环境 echo echo 访问http://localhost:8188 } case ${1:-} in --help|-h) echo 用法./setup_comfyui.sh echo CPU 模式TORCH_CUDAcpu ./setup_comfyui.sh exit 0 ;; esac main进行一键安装chmod x setup_comfyui.sh ./setup_comfyui.sh启动 ComfyUIcd ~/ComfyUI uv run python main.py打开浏览器访问http://localhost:8188