Last active
July 23, 2025 19:42
-
-
Save doggeddalle/0bf1b600b76f4a17f42031970f245f87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "--- ComfyUI Installation Script for alex ---" | |
| echo "Targeting NVIDIA RTX 3090, PyTorch with CUDA 12.8, Python 3.12, GCC12." | |
| # --- Configuration --- | |
| COMFYUI_DIR=$(pwd) | |
| VENV_DIR="${COMFYUI_DIR}/venv" | |
| PYTHON_VERSION="3.12" | |
| COMFYUI_REPO="https://github.com/comfyanonymous/ComfyUI.git" | |
| SAGEATTENTION_REPO="https://github.com/thu-ml/SageAttention.git" | |
| XFORMERS_REPO="https://github.com/facebookresearch/xformers.git" # Official xformers repo | |
| COMFYUI_MANAGER_REPO="https://github.com/Comfy-Org/ComfyUI-Manager.git" | |
| # Specific PyTorch index URL for stable CUDA 12.8 | |
| PYTORCH_CUDA_INDEX_URL="https://download.pytorch.org/whl/cu128" | |
| # --- Helper Functions --- | |
| # Function to check if a Python module is importable within the activated venv | |
| check_module_import() { | |
| local module_name="$1" | |
| # Ensure venv is activated before checking | |
| if [ -z "${VIRTUAL_ENV}" ]; then | |
| echo "Error: Virtual environment not activated. Cannot check module import for ${module_name}." | |
| return 1 | |
| fi | |
| python -c "import ${module_name}" &> /dev/null | |
| return $? | |
| } | |
| # Function to check if PyTorch is installed and CUDA enabled | |
| check_pytorch_cuda() { | |
| if [ -z "${VIRTUAL_ENV}" ]; then | |
| echo "Error: Virtual environment not activated. Cannot check PyTorch CUDA status." | |
| return 1 | |
| fi | |
| python -c " | |
| import torch | |
| if torch.cuda.is_available(): | |
| print('PyTorch with CUDA is available.') | |
| else: | |
| raise RuntimeError('PyTorch CUDA is not available.') | |
| " &> /dev/null | |
| return $? | |
| } | |
| # --- Prerequisites Check --- | |
| echo "" | |
| echo "Checking for essential build tools..." | |
| if ! command -v git &> /dev/null; then | |
| echo "Error: git is not installed. Please install it with 'sudo pacman -S git'." | |
| exit 1 | |
| fi | |
| if ! command -v python${PYTHON_VERSION} &> /dev/null; then | |
| echo "Error: Python ${PYTHON_VERSION} is not installed. Please install it, e.g., 'sudo pacman -S python'." | |
| exit 1 | |
| fi | |
| if ! command -v cmake &> /dev/null; then | |
| echo "Error: cmake is not installed. Please install it with 'sudo pacman -S cmake'." | |
| exit 1 | |
| fi | |
| # --- Explicitly setting GCC 12 for compilation --- | |
| if command -v gcc-12 &> /dev/null && command -v g++-12 &> /dev/null; then | |
| echo "Found gcc-12 and g++-12. Setting CC and CXX environment variables for builds." | |
| export CC="gcc-12" | |
| export CXX="g++-12" | |
| echo "CC is set to: ${CC}" | |
| echo "CXX is set to: ${CXX}" | |
| else | |
| echo "Error: Could not find gcc-12 or g++-12 in PATH. Please ensure they are installed and accessible." | |
| echo "You might need to adjust the script to point to the exact path if they are not in standard locations." | |
| exit 1 | |
| fi | |
| # --- ComfyUI Cloning --- | |
| echo "" | |
| echo "ComfyUI repository setup..." | |
| if [ ! -d "${COMFYUI_DIR}/ComfyUI" ]; then | |
| git clone "${COMFYUI_REPO}" "${COMFYUI_DIR}/ComfyUI" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone ComfyUI repository." | |
| exit 1 | |
| fi | |
| else | |
| echo "ComfyUI directory already exists. Pulling latest changes." | |
| (cd "${COMFYUI_DIR}/ComfyUI" && git pull) | |
| fi | |
| # --- Virtual Environment Setup --- | |
| echo "" | |
| echo "Setting up Python virtual environment at ${VENV_DIR}..." | |
| if [ ! -d "${VENV_DIR}" ]; then | |
| python${PYTHON_VERSION} -m venv "${VENV_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to create virtual environment." | |
| exit 1 | |
| fi | |
| echo "Virtual environment created." | |
| else | |
| echo "Virtual environment already exists." | |
| fi | |
| # Activate the virtual environment | |
| source "${VENV_DIR}/bin/activate" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to activate virtual environment." | |
| exit 1 | |
| fi | |
| echo "Virtual environment activated." | |
| # --- Python Package Installation --- | |
| echo "" | |
| echo "Installing/Updating core PyTorch, torchvision, and torchaudio with CUDA 12.8 support..." | |
| if check_pytorch_cuda; then | |
| echo "PyTorch with CUDA is already installed. Skipping." | |
| else | |
| echo "Attempting to uninstall existing PyTorch installations before clean install..." | |
| pip uninstall -y torch torchvision torchaudio 2>/dev/null | |
| pip install torch torchvision torchaudio --extra-index-url "${PYTORCH_CUDA_INDEX_URL}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install PyTorch with CUDA 12.8 support. Check your CUDA setup and network connection." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "PyTorch, torchvision, and torchaudio installed for CUDA 12.8." | |
| fi | |
| echo "" | |
| echo "Installing ComfyUI's core requirements..." | |
| pip install -r "${COMFYUI_DIR}/ComfyUI/requirements.txt" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install ComfyUI requirements. Check the log for specific package errors." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "ComfyUI requirements installed." | |
| # --- Triton Installation (Latest) --- | |
| echo "" | |
| echo "Installing latest Triton..." | |
| if check_module_import "triton"; then | |
| echo "Triton is already installed. Skipping." | |
| else | |
| pip install --upgrade triton | |
| if [ $? -ne 0 ]; then | |
| echo "Warning: Failed to install Triton directly. This might be due to a missing pre-built wheel." | |
| echo "Pip will attempt to build from source if possible. Ensure 'cmake' and build-essential packages are present." | |
| fi | |
| echo "Triton installation attempted." | |
| fi | |
| # --- SageAttention Installation (from source) --- | |
| echo "" | |
| echo "SageAttention 2++ setup..." | |
| SAGEATTENTION_DIR="${COMFYUI_DIR}/SageAttention" | |
| if [ ! -d "${SAGEATTENTION_DIR}" ]; then | |
| git clone "${SAGEATTENTION_REPO}" "${SAGEATTENTION_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone SageAttention repository." | |
| deactivate | |
| exit 1 | |
| fi | |
| else | |
| echo "SageAttention directory already exists. Pulling latest changes." | |
| (cd "${SAGEATTENTION_DIR}" && git pull) | |
| fi | |
| echo "Installing SageAttention from source (no build isolation)..." | |
| if check_module_import "sageattention"; then | |
| echo "SageAttention is already installed. Skipping build." | |
| else | |
| (cd "${SAGEATTENTION_DIR}" && pip install -e . --no-build-isolation) | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to build and install SageAttention. Check build logs for details." | |
| echo "Ensure your CUDA Toolkit is properly installed and accessible, and that GCC 12 is correctly configured via CC/CXX." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "SageAttention 2++ installed." | |
| fi | |
| # --- xFormers Installation (from source) --- | |
| echo "" | |
| echo "xFormers setup..." | |
| XFORMERS_DIR="${COMFYUI_DIR}/xformers" | |
| if [ ! -d "${XFORMERS_DIR}" ]; then | |
| git clone "${XFORMERS_REPO}" "${XFORMERS_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone xFormers repository." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "Initializing and updating xFormers submodules..." | |
| (cd "${XFORMERS_DIR}" && git submodule update --init --recursive) | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to update xFormers submodules. This is required for compilation." | |
| deactivate | |
| exit 1 | |
| fi | |
| else | |
| echo "xFormers directory already exists. Pulling latest changes and updating submodules." | |
| (cd "${XFORMERS_DIR}" && git pull && git submodule update --init --recursive) | |
| fi | |
| echo "Installing xFormers from source (this may take a while, no build isolation)..." | |
| if check_module_import "xformers"; then | |
| echo "xFormers is already installed. Skipping build." | |
| else | |
| (cd "${XFORMERS_DIR}" && pip install -e . --no-build-isolation) | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to build and install xFormers. Check build logs for details." | |
| echo "Ensure your CUDA Toolkit is properly installed and accessible, and that GCC 12 is correctly configured via CC/CXX." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "xFormers installed." | |
| fi | |
| # --- ComfyUI-Manager Installation --- | |
| echo "" | |
| echo "ComfyUI-Manager setup..." | |
| COMFYUI_MANAGER_DIR="${COMFYUI_DIR}/ComfyUI/custom_nodes/ComfyUI-Manager" | |
| mkdir -p "${COMFYUI_DIR}/ComfyUI/custom_nodes" # Ensure custom_nodes directory exists | |
| if [ ! -d "${COMFYUI_MANAGER_DIR}" ]; then | |
| echo "Cloning ComfyUI-Manager repository..." | |
| git clone "${COMFYUI_MANAGER_REPO}" "${COMFYUI_MANAGER_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone ComfyUI-Manager repository." | |
| echo "You may need to install it manually later or check network connectivity." | |
| else | |
| echo "ComfyUI-Manager cloned successfully." | |
| if [ -f "${COMFYUI_MANAGER_DIR}/requirements.txt" ]; then | |
| echo "Installing ComfyUI-Manager specific requirements (if any)..." | |
| pip install -r "${COMFYUI_MANAGER_DIR}/requirements.txt" | |
| fi | |
| fi | |
| else | |
| echo "ComfyUI-Manager directory already exists. Pulling latest changes." | |
| (cd "${COMFYUI_MANAGER_DIR}" && git pull) | |
| if [ $? -ne 0 ]; then | |
| echo "Warning: Failed to pull latest changes for ComfyUI-Manager." | |
| else | |
| echo "ComfyUI-Manager updated." | |
| if [ -f "${COMFYUI_MANAGER_DIR}/requirements.txt" ]; then | |
| echo "Re-installing ComfyUI-Manager specific requirements (if any)..." | |
| pip install -r "${COMFYUI_MANAGER_DIR}/requirements.txt" | |
| fi | |
| fi | |
| fi | |
| # --- Final Message --- | |
| echo "" | |
| echo "--- ComfyUI installation process completed" | |
| # Deactivate the environment at the end of the script to not leave it active globally | |
| deactivate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment