Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Allow install_python_stack to run on Colab (#4633)

Roland Tannouse79a178200b4
diff --git a/studio/Unsloth_Studio_Colab.ipynb b/studio/Unsloth_Studio_Colab.ipynb
index c3aec048207..46e2067ba73 100644
--- a/studio/Unsloth_Studio_Colab.ipynb
+++ b/studio/Unsloth_Studio_Colab.ipynb
@@ -64,7 +64,7 @@
"id": "27e68f91"
},
"outputs": [],
- "source": "!git clone --depth 1 --branch main https://github.com/unslothai/unsloth.git\n%cd /content/unsloth\n!chmod +x studio/setup.sh && ./studio/setup.sh --local"
+ "source": "!git clone --depth 1 --branch main https://github.com/unslothai/unsloth.git\n%cd /content/unsloth\n!chmod +x studio/setup.sh && ./studio/setup.sh"
},
{
"cell_type": "markdown",
diff --git a/studio/backend/colab.py b/studio/backend/colab.py
index deddf28087a..efd0e10bdbd 100644
--- a/studio/backend/colab.py
+++ b/studio/backend/colab.py
@@ -18,90 +18,6 @@ if _backend_dir not in sys.path:
import _platform_compat # noqa: F401
-def _is_colab() -> bool:
- """Detect Google Colab by checking for COLAB_ prefixed env vars."""
- import os
-
- return any(k.startswith("COLAB_") for k in os.environ)
-
-
-def _pip_install_backend_deps() -> None:
- """Install Studio backend dependencies directly into the current Python.
-
- Used on Colab when the Studio venv does not exist (install.sh was not
- run). Reads the requirements from studio.txt next to this file.
-
- Version constraints are stripped entirely so pip keeps whatever Colab
- already has installed (e.g. huggingface-hub, datasets, transformers)
- and only installs genuinely missing packages like structlog, fastapi.
- """
- import re
- import subprocess
-
- req_file = Path(__file__).parent / "requirements" / "studio.txt"
- if not req_file.exists():
- return
-
- packages = []
- for line in req_file.read_text().splitlines():
- line = line.strip()
- if not line or line.startswith("#"):
- continue
- # Strip all version constraints -- just keep the package name
- pkg_name = re.split(r"[><=!~;\[]", line)[0].strip()
- if pkg_name:
- packages.append(pkg_name)
-
- if not packages:
- return
- print("Installing Studio backend dependencies ...")
- subprocess.check_call(
- [sys.executable, "-m", "pip", "install", "-q"] + packages,
- )
-
- # Colab ships huggingface-hub 0.36.x which removed is_offline_mode,
- # breaking transformers. Upgrade to 1.0+ which restored it.
- try:
- from huggingface_hub import is_offline_mode # noqa: F401
- except ImportError:
- print("Upgrading huggingface-hub (is_offline_mode missing) ...")
- subprocess.check_call(
- [sys.executable, "-m", "pip", "install", "-q", "huggingface-hub>=1.0"],
- )
-
-
-def _bootstrap_studio_venv() -> None:
- """Expose the Studio venv's site-packages to the current interpreter.
-
- On Colab, notebook cells run outside the venv subshell. Instead of
- installing the full stack into system Python, we prepend the venv's
- site-packages so that packages like structlog, fastapi, etc. are
- importable from notebook cells and take priority over system copies.
-
- If the venv does not exist and we are running on Colab, fall back to
- pip-installing the backend dependencies into the current environment
- so that imports like structlog and fastapi succeed.
- """
- venv_lib = Path.home() / ".unsloth" / "studio" / "unsloth_studio" / "lib"
- if not venv_lib.exists():
- if _is_colab():
- _pip_install_backend_deps()
- return
- import warnings
-
- warnings.warn(
- f"Studio venv not found at {venv_lib.parent} -- run 'unsloth studio setup' first",
- stacklevel = 2,
- )
- return
- for sp in venv_lib.glob("python*/site-packages"):
- sp_str = str(sp)
- if sp_str not in sys.path:
- sys.path.insert(0, sp_str)
-
-
-_bootstrap_studio_venv()
-
from loggers import get_logger
logger = get_logger(__name__)
diff --git a/studio/setup.sh b/studio/setup.sh
index 4e46a12fe0c..6f43446757c 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -346,13 +346,15 @@ fi
# ── Check if Python deps need updating ──
# Compare installed package version against PyPI latest.
# Skip all Python dependency work if versions match (fast update path).
-# On Colab (no venv), skip the entire venv-dependent Python deps section.
+# On Colab (no venv), skip this version check (it needs $VENV_DIR/bin/python)
+# but still run install_python_stack below (it uses sys.executable).
_SKIP_PYTHON_DEPS=false
+_SKIP_VERSION_CHECK=false
if [ "$_COLAB_NO_VENV" = true ]; then
- _SKIP_PYTHON_DEPS=true
+ _SKIP_VERSION_CHECK=true
fi
_PKG_NAME="${STUDIO_PACKAGE_NAME:-unsloth}"
-if [ "$_SKIP_PYTHON_DEPS" != true ] && [ "${SKIP_STUDIO_BASE:-0}" != "1" ] && [ "${STUDIO_LOCAL_INSTALL:-0}" != "1" ]; then
+if [ "$_SKIP_VERSION_CHECK" != true ] && [ "${SKIP_STUDIO_BASE:-0}" != "1" ] && [ "${STUDIO_LOCAL_INSTALL:-0}" != "1" ]; then
# Only check when NOT called from install.sh (which just installed the package)
INSTALLED_VER=$("$VENV_DIR/bin/python" -c "
from importlib.metadata import version