Spaces:
Running
on
Zero
Running
on
Zero
Update setup_blender.sh
Browse files- setup_blender.sh +68 -67
setup_blender.sh
CHANGED
@@ -3,78 +3,103 @@ set -e
|
|
3 |
|
4 |
# --- Configuration ---
|
5 |
BLENDER_VERSION="4.2.0"
|
6 |
-
BLENDER_MAJOR_MINOR="4.2"
|
7 |
BLENDER_PYTHON_VERSION="python3.11" # Should match the -dev package (e.g., python3.11-dev)
|
8 |
BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
9 |
BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
# Path to the cloned UniRig repository in the Space
|
16 |
-
UNIRIG_REPO_CLONE_DIR="/home/user/app/UniRig" # Standard path
|
17 |
|
18 |
TORCH_VERSION="2.3.1"
|
19 |
-
TORCHVISION_VERSION="0.18.1"
|
20 |
-
NUMPY_VERSION="1.26.4"
|
21 |
-
TARGET_CUDA_VERSION_SHORT="cu121"
|
22 |
-
|
23 |
TORCH_INDEX_URL="https://download.pytorch.org/whl/${TARGET_CUDA_VERSION_SHORT}"
|
24 |
PYG_FIND_LINKS_URL="https://data.pyg.org/whl/torch-${TORCH_VERSION}+${TARGET_CUDA_VERSION_SHORT}.html"
|
25 |
-
SPCONV_PACKAGE="spconv-${TARGET_CUDA_VERSION_SHORT}"
|
26 |
|
27 |
# --- Set Environment Variables for Build ---
|
28 |
-
export CUDA_HOME=${CUDA_HOME:-/usr/local/cuda}
|
29 |
-
export PATH="${CUDA_HOME}/bin:${PATH}"
|
30 |
-
export MAX_JOBS
|
31 |
-
|
32 |
-
#
|
33 |
-
PYTHON_INCLUDE_DIR="/usr/include/python${BLENDER_PYTHON_VERSION#python}" # Extracts "3.11" from "python3.11"
|
34 |
export CPATH="${PYTHON_INCLUDE_DIR}:${CPATH}"
|
35 |
export C_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${C_INCLUDE_PATH}"
|
36 |
export CPLUS_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${CPLUS_INCLUDE_PATH}"
|
37 |
|
|
|
|
|
|
|
38 |
echo "Using CUDA_HOME=${CUDA_HOME}"
|
39 |
-
echo "
|
40 |
echo "CPATH set to: ${CPATH}"
|
41 |
-
echo "C_INCLUDE_PATH set to: ${C_INCLUDE_PATH}"
|
42 |
-
echo "CPLUS_INCLUDE_PATH set to: ${CPLUS_INCLUDE_PATH}"
|
43 |
echo "Expected Python include directory: ${PYTHON_INCLUDE_DIR}"
|
44 |
-
|
45 |
if [ -f "${PYTHON_INCLUDE_DIR}/Python.h" ]; then
|
46 |
echo "Found Python.h at ${PYTHON_INCLUDE_DIR}/Python.h"
|
47 |
else
|
48 |
echo "WARNING: Python.h NOT FOUND at ${PYTHON_INCLUDE_DIR}/Python.h. Ensure python${BLENDER_PYTHON_VERSION#python}-dev is in packages.txt and installed."
|
49 |
fi
|
50 |
|
51 |
-
|
52 |
# --- Download and Extract Blender ---
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
else
|
57 |
-
echo "Blender
|
58 |
fi
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
else
|
65 |
-
echo "Blender
|
66 |
fi
|
67 |
-
echo "Extraction complete."
|
68 |
|
69 |
-
# --- Create Blender Symlink ---
|
70 |
-
echo "Creating symlink for Blender executable..."
|
71 |
-
ln -sf ${INSTALL_DIR}/blender /usr/local/bin/blender
|
72 |
-
echo "Symlink created."
|
73 |
|
74 |
# --- Install Dependencies into Blender's Python ---
|
75 |
echo "Installing dependencies into Blender's Python (${BLENDER_PY_EXEC})..."
|
76 |
if [ ! -f "${BLENDER_PY_EXEC}" ]; then
|
77 |
echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
|
|
|
78 |
exit 1
|
79 |
fi
|
80 |
if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
|
@@ -83,37 +108,13 @@ if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
|
|
83 |
fi
|
84 |
|
85 |
echo "Upgrading pip for Blender Python..."
|
86 |
-
# ** ADDED -vvv for verbosity **
|
87 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir --upgrade pip setuptools wheel -vvv
|
88 |
|
89 |
-
|
90 |
-
#
|
91 |
-
"${
|
92 |
-
torch==${TORCH_VERSION} \
|
93 |
-
torchvision==${TORCHVISION_VERSION} \
|
94 |
-
--index-url ${TORCH_INDEX_URL} -vvv
|
95 |
-
|
96 |
-
echo "2. Installing dependencies from ${UNIRIG_REQS_FILE_IN_SPACE} (includes bpy, flash_attn)..."
|
97 |
-
# flash-attn compilation might also benefit from CPATH
|
98 |
-
# ** ADDED -vvv for verbosity **
|
99 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE_IN_SPACE}" -vvv
|
100 |
|
101 |
-
echo "3. Installing ${SPCONV_PACKAGE}..."
|
102 |
-
# ** ADDED -vvv for verbosity **
|
103 |
-
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir ${SPCONV_PACKAGE} -vvv
|
104 |
-
|
105 |
-
echo "4. Installing torch-scatter and torch-cluster..."
|
106 |
-
# The CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH set above should help this step
|
107 |
-
# ** ADDED -vvv for verbosity **
|
108 |
-
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
|
109 |
-
torch-scatter \
|
110 |
-
torch-cluster \
|
111 |
-
-f "${PYG_FIND_LINKS_URL}" -vvv
|
112 |
-
|
113 |
-
echo "5. Installing numpy==${NUMPY_VERSION}..."
|
114 |
-
# ** ADDED -vvv for verbosity **
|
115 |
-
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir numpy==${NUMPY_VERSION} -vvv
|
116 |
-
|
117 |
echo "Dependency installation for Blender's Python complete."
|
118 |
|
119 |
# --- FIX: Ensure UniRig/src is treated as a package ---
|
@@ -130,13 +131,13 @@ if [ -d "${UNIRIG_SRC_DIR}" ]; then
|
|
130 |
else
|
131 |
echo "WARNING: UniRig src directory not found at ${UNIRIG_SRC_DIR}. Cannot create __init__.py."
|
132 |
fi
|
133 |
-
# --- END FIX ---
|
134 |
|
135 |
# (Optional) VRM Addon installation
|
136 |
-
VRM_ADDON_REL_PATH="blender/add-on-vrm-v2.20.77_modified.zip"
|
137 |
ABSOLUTE_ADDON_PATH="${UNIRIG_REPO_CLONE_DIR}/${VRM_ADDON_REL_PATH}"
|
138 |
if [ -f "${ABSOLUTE_ADDON_PATH}" ]; then
|
139 |
echo "Installing optional VRM addon for Blender..."
|
|
|
140 |
(cd "${UNIRIG_REPO_CLONE_DIR}" && \
|
141 |
"${BLENDER_PY_EXEC}" -c "import bpy, os; bpy.ops.preferences.addon_install(overwrite=True, filepath=os.path.abspath('${VRM_ADDON_REL_PATH}')); bpy.ops.preferences.addon_enable(module='io_scene_vrm'); print('VRM Addon installed and enabled.')")
|
142 |
echo "VRM addon installation attempted."
|
@@ -148,5 +149,5 @@ fi
|
|
148 |
echo "Cleaning up downloaded Blender tarball..."
|
149 |
rm -f /tmp/${BLENDER_TARBALL}
|
150 |
echo "Cleanup complete."
|
151 |
-
echo "Blender setup finished successfully."
|
152 |
-
|
|
|
3 |
|
4 |
# --- Configuration ---
|
5 |
BLENDER_VERSION="4.2.0"
|
6 |
+
BLENDER_MAJOR_MINOR="4.2" # Corresponds to Blender's internal versioned Python directory
|
7 |
BLENDER_PYTHON_VERSION="python3.11" # Should match the -dev package (e.g., python3.11-dev)
|
8 |
BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
9 |
BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
10 |
+
|
11 |
+
# ** MODIFIED FOR LOCAL BLENDER INSTALLATION **
|
12 |
+
# Assuming this script is run from /home/user/app (standard for HF Spaces app.py)
|
13 |
+
APP_DIR="/home/user/app" # Or use $(pwd) if script is guaranteed to be in app root
|
14 |
+
BLENDER_INSTALL_BASE="${APP_DIR}/blender_installation" # Base directory for Blender versions
|
15 |
+
INSTALL_DIR="${BLENDER_INSTALL_BASE}/blender-${BLENDER_VERSION}-linux-x64" # Specific version install
|
16 |
+
LOCAL_BIN_DIR="${APP_DIR}/local_bin" # For local symlinks, if used
|
17 |
+
|
18 |
BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
|
19 |
|
20 |
+
UNIRIG_REQS_FILE_IN_SPACE="${APP_DIR}/unirig_requirements.txt"
|
21 |
+
UNIRIG_REPO_CLONE_DIR="${APP_DIR}/UniRig"
|
|
|
|
|
22 |
|
23 |
TORCH_VERSION="2.3.1"
|
24 |
+
# TORCHVISION_VERSION="0.18.1" # Already in unirig_requirements.txt
|
25 |
+
# NUMPY_VERSION="1.26.4" # Already in unirig_requirements.txt
|
26 |
+
TARGET_CUDA_VERSION_SHORT="cu121"
|
|
|
27 |
TORCH_INDEX_URL="https://download.pytorch.org/whl/${TARGET_CUDA_VERSION_SHORT}"
|
28 |
PYG_FIND_LINKS_URL="https://data.pyg.org/whl/torch-${TORCH_VERSION}+${TARGET_CUDA_VERSION_SHORT}.html"
|
29 |
+
# SPCONV_PACKAGE="spconv-${TARGET_CUDA_VERSION_SHORT}" # Already in unirig_requirements.txt
|
30 |
|
31 |
# --- Set Environment Variables for Build ---
|
32 |
+
export CUDA_HOME=${CUDA_HOME:-/usr/local/cuda} # Keep for system CUDA if needed by compilations
|
33 |
+
export PATH="${CUDA_HOME}/bin:${LOCAL_BIN_DIR}:${PATH}" # Add local_bin to PATH early
|
34 |
+
export MAX_JOBS=${MAX_JOBS:-4} # For compilation processes
|
35 |
+
|
36 |
+
PYTHON_INCLUDE_DIR="/usr/include/python${BLENDER_PYTHON_VERSION#python}" # e.g., /usr/include/python3.11
|
|
|
37 |
export CPATH="${PYTHON_INCLUDE_DIR}:${CPATH}"
|
38 |
export C_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${C_INCLUDE_PATH}"
|
39 |
export CPLUS_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${CPLUS_INCLUDE_PATH}"
|
40 |
|
41 |
+
echo "--- Setup Script Start ---"
|
42 |
+
echo "Target Blender Installation Directory: ${INSTALL_DIR}"
|
43 |
+
echo "Blender Python Executable: ${BLENDER_PY_EXEC}"
|
44 |
echo "Using CUDA_HOME=${CUDA_HOME}"
|
45 |
+
echo "Initial PATH: ${PATH}"
|
46 |
echo "CPATH set to: ${CPATH}"
|
|
|
|
|
47 |
echo "Expected Python include directory: ${PYTHON_INCLUDE_DIR}"
|
48 |
+
|
49 |
if [ -f "${PYTHON_INCLUDE_DIR}/Python.h" ]; then
|
50 |
echo "Found Python.h at ${PYTHON_INCLUDE_DIR}/Python.h"
|
51 |
else
|
52 |
echo "WARNING: Python.h NOT FOUND at ${PYTHON_INCLUDE_DIR}/Python.h. Ensure python${BLENDER_PYTHON_VERSION#python}-dev is in packages.txt and installed."
|
53 |
fi
|
54 |
|
|
|
55 |
# --- Download and Extract Blender ---
|
56 |
+
# Create the local installation base directory
|
57 |
+
mkdir -p "${BLENDER_INSTALL_BASE}"
|
58 |
+
mkdir -p "${LOCAL_BIN_DIR}" # Ensure local_bin exists
|
59 |
+
|
60 |
+
if [ ! -d "${INSTALL_DIR}/blender-${BLENDER_VERSION}-linux-x64" ]; then # Check if specific version is already extracted
|
61 |
+
echo "Downloading Blender ${BLENDER_VERSION}..."
|
62 |
+
if [ ! -f "/tmp/${BLENDER_TARBALL}" ]; then
|
63 |
+
wget -nv -O "/tmp/${BLENDER_TARBALL}" ${BLENDER_URL}
|
64 |
+
else
|
65 |
+
echo "Blender tarball /tmp/${BLENDER_TARBALL} already downloaded."
|
66 |
+
fi
|
67 |
+
|
68 |
+
echo "Extracting Blender to ${BLENDER_INSTALL_BASE}..."
|
69 |
+
# Extracts to a subdirectory like blender-4.2.0-linux-x64 inside BLENDER_INSTALL_BASE
|
70 |
+
tar -xJf "/tmp/${BLENDER_TARBALL}" -C "${BLENDER_INSTALL_BASE}"
|
71 |
+
# The tarball extracts into a folder named "blender-4.2.0-linux-x64", so INSTALL_DIR should be correct.
|
72 |
+
if [ -d "${INSTALL_DIR}" ]; then
|
73 |
+
echo "Blender extracted successfully to ${INSTALL_DIR}"
|
74 |
+
else
|
75 |
+
echo "ERROR: Blender extraction failed or extracted to an unexpected path. Expected: ${INSTALL_DIR}"
|
76 |
+
# List contents of BLENDER_INSTALL_BASE for debugging
|
77 |
+
ls -la "${BLENDER_INSTALL_BASE}"
|
78 |
+
exit 1
|
79 |
+
fi
|
80 |
else
|
81 |
+
echo "Blender already appears to be extracted to ${INSTALL_DIR}."
|
82 |
fi
|
83 |
+
echo "Extraction complete."
|
84 |
|
85 |
+
# --- Create Blender Symlink (Optional - to local_bin) ---
|
86 |
+
# This system symlink would require sudo and likely fail:
|
87 |
+
# ln -sf ${INSTALL_DIR}/blender /usr/local/bin/blender
|
88 |
+
# Instead, create a local symlink if desired, and ensure local_bin is in PATH (done above)
|
89 |
+
if [ -f "${INSTALL_DIR}/blender" ]; then
|
90 |
+
echo "Creating local symlink for Blender executable in ${LOCAL_BIN_DIR}..."
|
91 |
+
ln -sf "${INSTALL_DIR}/blender" "${LOCAL_BIN_DIR}/blender"
|
92 |
+
echo "Local symlink created at ${LOCAL_BIN_DIR}/blender. Make sure ${LOCAL_BIN_DIR} is in your PATH."
|
93 |
else
|
94 |
+
echo "WARNING: Blender executable not found at ${INSTALL_DIR}/blender. Cannot create symlink."
|
95 |
fi
|
|
|
96 |
|
|
|
|
|
|
|
|
|
97 |
|
98 |
# --- Install Dependencies into Blender's Python ---
|
99 |
echo "Installing dependencies into Blender's Python (${BLENDER_PY_EXEC})..."
|
100 |
if [ ! -f "${BLENDER_PY_EXEC}" ]; then
|
101 |
echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
|
102 |
+
echo "Check Blender extraction and paths."
|
103 |
exit 1
|
104 |
fi
|
105 |
if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
|
|
|
108 |
fi
|
109 |
|
110 |
echo "Upgrading pip for Blender Python..."
|
|
|
111 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir --upgrade pip setuptools wheel -vvv
|
112 |
|
113 |
+
# Simplified: Install all from unirig_requirements.txt
|
114 |
+
# Ensure unirig_requirements.txt has all specific versions and index URLs for torch, pyg, spconv, etc.
|
115 |
+
echo "Installing all dependencies from ${UNIRIG_REQS_FILE_IN_SPACE}..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE_IN_SPACE}" -vvv
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
echo "Dependency installation for Blender's Python complete."
|
119 |
|
120 |
# --- FIX: Ensure UniRig/src is treated as a package ---
|
|
|
131 |
else
|
132 |
echo "WARNING: UniRig src directory not found at ${UNIRIG_SRC_DIR}. Cannot create __init__.py."
|
133 |
fi
|
|
|
134 |
|
135 |
# (Optional) VRM Addon installation
|
136 |
+
VRM_ADDON_REL_PATH="blender/add-on-vrm-v2.20.77_modified.zip" # Relative to UniRig repo root
|
137 |
ABSOLUTE_ADDON_PATH="${UNIRIG_REPO_CLONE_DIR}/${VRM_ADDON_REL_PATH}"
|
138 |
if [ -f "${ABSOLUTE_ADDON_PATH}" ]; then
|
139 |
echo "Installing optional VRM addon for Blender..."
|
140 |
+
# Ensure CWD is UniRig repo for relative path in addon script if any
|
141 |
(cd "${UNIRIG_REPO_CLONE_DIR}" && \
|
142 |
"${BLENDER_PY_EXEC}" -c "import bpy, os; bpy.ops.preferences.addon_install(overwrite=True, filepath=os.path.abspath('${VRM_ADDON_REL_PATH}')); bpy.ops.preferences.addon_enable(module='io_scene_vrm'); print('VRM Addon installed and enabled.')")
|
143 |
echo "VRM addon installation attempted."
|
|
|
149 |
echo "Cleaning up downloaded Blender tarball..."
|
150 |
rm -f /tmp/${BLENDER_TARBALL}
|
151 |
echo "Cleanup complete."
|
152 |
+
echo "Blender setup finished successfully. Blender is in ${INSTALL_DIR}"
|
153 |
+
echo "--- Setup Script End ---"
|