Mesh_Rigger / setup_blender.sh
jkorstad's picture
Update setup_blender.sh
a1ddb51 verified
raw
history blame
3.21 kB
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Configuration ---
BLENDER_VERSION="4.2.0"
BLENDER_MAJOR_MINOR="4.2" # Matches the version directory structure
BLENDER_PYTHON_VERSION="python3.11" # Blender 4.2 uses Python 3.11
BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
INSTALL_DIR="/opt/blender-${BLENDER_VERSION}-linux-x64"
BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
# Assuming unirig_requirements.txt is in the root directory alongside this script and app.py
# If UniRig repo is cloned first, adjust path e.g., "UniRig/unirig_requirements.txt"
UNIRIG_REQS_FILE="unirig_requirements.txt"
# Define the specific torch version and index URL (matching unirig_requirements.txt)
TORCH_VERSION="2.3.1"
TORCHVISION_VERSION="0.18.1"
TORCH_INDEX_URL="https://download.pytorch.org/whl/cu121" # Make sure this matches your target CUDA
# --- Download and Extract Blender ---
echo "Downloading Blender ${BLENDER_VERSION}..."
wget -nv -O /tmp/${BLENDER_TARBALL} ${BLENDER_URL}
echo "Download complete."
echo "Extracting Blender to ${INSTALL_DIR}..."
mkdir -p /opt # Ensure /opt exists
tar -xJf /tmp/${BLENDER_TARBALL} -C /opt
echo "Extraction complete."
# --- Create Blender Symlink ---
echo "Creating symlink for Blender executable..."
ln -sf ${INSTALL_DIR}/blender /usr/local/bin/blender # Use -f to force overwrite if exists
echo "Symlink created."
# --- Install UniRig Dependencies into Blender's Python ---
echo "Installing UniRig Python dependencies into Blender's Python (${BLENDER_PYTHON_VERSION})..."
if [ ! -f "${BLENDER_PY_EXEC}" ]; then
echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC} after extraction!"
exit 1
fi
if [ ! -f "${UNIRIG_REQS_FILE}" ]; then
echo "ERROR: UniRig requirements file not found at ${UNIRIG_REQS_FILE}!"
echo "Ensure this file exists in the root directory."
exit 1
fi
# Upgrade pip within Blender's Python environment
echo "Upgrading pip for Blender Python..."
"${BLENDER_PY_EXEC}" -m pip install --upgrade pip setuptools wheel
# --- Install PyTorch and Torchvision FIRST ---
# This is crucial because some packages (like torch-scatter) need torch during their own setup
echo "Installing PyTorch ${TORCH_VERSION} and Torchvision ${TORCHVISION_VERSION} first..."
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
torch==${TORCH_VERSION} \
torchvision==${TORCHVISION_VERSION} \
--index-url ${TORCH_INDEX_URL}
echo "PyTorch and Torchvision installation complete."
# --- Install the rest of the packages from unirig_requirements.txt ---
# Pip will skip torch and torchvision if they are already installed at the correct version
echo "Installing remaining packages from ${UNIRIG_REQS_FILE}..."
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE}"
echo "UniRig dependency installation for Blender Python complete."
# --- Cleanup ---
echo "Cleaning up downloaded tarball..."
rm /tmp/${BLENDER_TARBALL}
echo "Cleanup complete."
echo "Blender setup finished successfully."