ComfyUI 安装教程:macOS 和 Linux 统一步骤

本教程将详细介绍如何在 macOS 和 Linux 上安装 ComfyUI。我们将从 安装 Anaconda 开始,到安装 PyTorch 和 ComfyUI,最后提供一些常见问题的解决方法。

macOS和linux安装步骤很相似

可以按照1️⃣安装anaconda2️⃣安装python3️⃣torch4️⃣comfyui

ComfyUI 安装教程:macOS 和 Linux 统一步骤

  • [1. 安装 Anaconda](#1. 安装 Anaconda)
    • [1.1 下载并安装 Anaconda](#1.1 下载并安装 Anaconda)
  • [2. 创建 Python 虚拟环境](#2. 创建 Python 虚拟环境)
    • [2.1 创建并激活虚拟环境](#2.1 创建并激活虚拟环境)
    • [2.2 安装xcode(仅macOS)](#2.2 安装xcode(仅macOS))
  • [3. 安装 PyTorch](#3. 安装 PyTorch)
    • [3.1 安装 PyTorch(macOS无 GPU 支持)](#3.1 安装 PyTorch(macOS无 GPU 支持))
    • [3.2 安装PyTorch(Linux有GPU支持)](#3.2 安装PyTorch(Linux有GPU支持))
  • [4. 配置 PIP 缓存目录](#4. 配置 PIP 缓存目录)
    • [4.1 配置 PIP 缓存目录](#4.1 配置 PIP 缓存目录)
  • [5. 安装 ComfyUI](#5. 安装 ComfyUI)
    • [5.1 克隆并安装 ComfyUI](#5.1 克隆并安装 ComfyUI)
    • [5.2 安装插件管理器](#5.2 安装插件管理器)
    • [5.3 安装汉化插件(可选)](#5.3 安装汉化插件(可选))
    • [5.4 启动 ComfyUI](#5.4 启动 ComfyUI)
  • [6. 常见问题及解决方法](#6. 常见问题及解决方法)
    • [6.1 报错:`command not found: conda`](#6.1 报错:command not found: conda)
    • [6.2 报错:`Could not find a version that satisfies the requirement`](#6.2 报错:Could not find a version that satisfies the requirement)
    • [6.3 报错:`No space left on device`](#6.3 报错:No space left on device)

1. 安装 Anaconda

1.1 下载并安装 Anaconda

  1. 下载 Anaconda

    • 访问 Anaconda 官网
    • 选择适合你操作系统的 Anaconda 安装包(macOSLinux)。
  2. 安装 Anaconda

    打开终端并运行以下命令(假设你下载的是 Anaconda3-2023.x.x-MacOSX-x86_64.shAnaconda3-2023.x.x-Linux-x86_64.sh):

    bash 复制代码
    bash Anaconda3-2023.x.x-MacOSX-x86_64.sh  # 对于macOS
    bash Anaconda3-2023.x.x-Linux-x86_64.sh  # 对于Linux
  3. 按提示安装

    • 接受许可证(按 Enter 键确认)。
    • 选择安装路径(默认情况下为:/Users/your-username/anaconda3/home/your-username/anaconda3)。
    • 如果你不想修改安装路径,直接按 Enter 键。
  4. 设置 Anaconda 环境变量

    • macOS 上,编辑。~/.zshrc 文件(如果使用 bash ,则是。~/.bash_profile)。
    • Linux 上,编辑。~/.bashrc 文件

    打开文件进行编辑:

    bash 复制代码
    nano ~/.zshrc  # macOS 使用 zsh
    nano ~/.bashrc  # Linux 使用 bash

    在文件末尾添加以下内容:

    bash 复制代码
    export PATH="$HOME/anaconda3/bin:$PATH"

    保存并退出编辑器后,运行以下命令使修改生效:

    bash 复制代码
    source ~/.zshrc  # macOS
    source ~/.bashrc  # Linux
  5. 验证安装: 在终端中运行:

    bash 复制代码
    conda --version

如果安装成功,应该显示 Anaconda 的版本号。

2. 创建 Python 虚拟环境

2.1 创建并激活虚拟环境

  1. 使用 conda 创建一个新的 Python 3.12 虚拟环境:

    bash 复制代码
    conda create --name comfyui python=3.12
  2. 激活虚拟环境:

    bash 复制代码
    conda activate comfyui
  3. 验证 Python 版本:

    bash 复制代码
    python --version

    输出应该是 Python 3.12.x。

2.2 安装xcode(仅macOS)

打开终端,输入代码:

bash 复制代码
xcode-select --install

如果报错,也可以直接到app商店,下载xcode,安装即可

3. 安装 PyTorch

3.1 安装 PyTorch(macOS无 GPU 支持)

由于没有 GPU 支持,我们安装 PyTorch CPU 版本。运行以下命令:

  1. 安装 PyTorchTorchVisionTorchaudio

    bash 复制代码
    conda install pytorch torchvision torchaudio -c pytorch
  2. 若要安装 PyTorch Nightly 版本,可运行:

    bash 复制代码
    conda install pytorch torchvision torchaudio -c pytorch-nightly

    这会自动选择适合 CPU 的版本。

3.2 安装PyTorch(Linux有GPU支持)

  1. 安装 PyTorchTorchVisionTorchaudio

    bash 复制代码
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu112 -i https://pypi.tuna.tsinghua.edu.cn/simple

    注意自己的CUDA版本,安装对应的版本

4. 配置 PIP 缓存目录

为了避免缓存文件占满磁盘空间,我们可以设置 PIP 缓存目录。

4.1 配置 PIP 缓存目录

  1. 设置 PIP 缓存目录:

    bash 复制代码
    export PIP_CACHE_DIR="/data/osadm/cache"
  2. 要使其在每次打开终端时生效,请编辑 ~/.zshrc~/.bashrc 文件,添加:

    bash 复制代码
    export PIP_CACHE_DIR="/data/osadm/cache"
  3. 保存文件并使修改生效:

    bash 复制代码
    source ~/.zshrc  # macOS
    source ~/.bashrc  # Linux

5. 安装 ComfyUI

5.1 克隆并安装 ComfyUI

  1. 克隆 ComfyUI 仓库:

    bash 复制代码
    cd ~/
    git clone https://github.com/comfyanonymous/ComfyUI
    cd ComfyUI
  2. 安装 ComfyUI 依赖:

    bash 复制代码
    pip install -r requirements.txt

5.2 安装插件管理器

  1. 进入 custom_nodes 目录并克隆插件管理器:

    bash 复制代码
    cd ~/ComfyUI/custom_nodes
    git clone https://github.com/ltdrdata/ComfyUI-Manager.git
    cd ComfyUI-Manager
    pip install -r requirements.txt

5.3 安装汉化插件(可选)

  1. 如果需要汉化界面:

    bash 复制代码
    cd ..
    git clone https://github.com/AIGODLIKE/AIGODLIKE-COMFYUI-TRANSLATION.git

5.4 启动 ComfyUI

  1. 启动 ComfyUI:

    bash 复制代码
    cd ~/ComfyUI
    python main.py

6. 常见问题及解决方法

6.1 报错:command not found: conda

问题描述:

在安装 Anaconda 后,使用 conda 命令时显示 command not found 错误。

解决方法:

确保 conda 的路径已经正确添加到环境变量中。请按照以下步骤操作:

  1. 编辑 ~/.bashrc~/.zshrc 文件,确保添加以下行:

    bash 复制代码
    export PATH="$HOME/anaconda3/bin:$PATH"
  2. 然后运行以下命令,使修改生效:

    bash 复制代码
    source ~/.bashrc  # Linux
    source ~/.zshrc   # macOS
  3. 如果问题仍然存在,请确保你的 Anaconda 安装路径正确,并检查是否安装了多个版本的 Python。

6.2 报错:Could not find a version that satisfies the requirement

问题描述:

在安装依赖时遇到以下错误:

lua 复制代码
Could not find a version that satisfies the requirement <package-name>

解决方法:

这个错误通常是因为 PyPI 上没有找到对应版本的包。你可以尝试以下几种方式解决:

  1. 更新 pip:

    bash 复制代码
    pip install --upgrade pip
  2. 使用清华镜像源安装

    bash 复制代码
    pip install <package-name> -i https://pypi.tuna.tsinghua.edu.cn/simple
  3. 如果是 PyTorch 相关问题,确保使用与 Python 版本匹配的 PyTorch 安装命令。例如,使用 conda 安装,而不是 pip

6.3 报错:No space left on device

问题描述:

在运行某些安装命令时,遇到以下错误:

lua 复制代码
OSError: [Errno 28] No space left on device

解决方法:

  1. 检查磁盘空间:

    bash 复制代码
    df -h
  2. 清理无用的缓存或临时文件。你可以使用以下命令清理 PIP 缓存:

    bash 复制代码
    pip cache purge
  3. 如果你的系统磁盘空间不足,可以将安装路径或者缓存目录更改为其他磁盘(例如,/data/osadm/cache)。

相关推荐
___波子 Pro Max.1 小时前
vim modeline
linux·编辑器·vim
hunter2062062 小时前
ubuntu的terminator设置自动补全
linux·运维·ubuntu
泰山码3 小时前
Mac 终端命令大全
macos
阿雄不会写代码3 小时前
Linux Windows macOS如何安装Ollama
linux·windows·macos
ℳ₯㎕ddzོꦿ࿐3 小时前
通过AutoHotkey将Windows按键修改为Mac的快捷键并设置开机自启动
windows·macos
hunter2062063 小时前
ubuntu和手机之间如何传递消息
linux·ubuntu·智能手机
利来利往4 小时前
centos虚拟机迁移没有ip的问题
linux·运维·centos
不知 不知4 小时前
CentOS 7配置samba服务设置文件共享
linux·运维·centos
starjuly4 小时前
Centos执行yum命令报错
linux·运维·centos