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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix `unsloth run` on Windows: the venv entry point is unsloth.exe (#7718)
Daniel Han9fe5dd9eb403
diff --git a/tests/studio/test_run_windows_entry_point.py b/tests/studio/test_run_windows_entry_point.pynew file mode 100644index 00000000000..24b2eff8d2f--- /dev/null+++ b/tests/studio/test_run_windows_entry_point.py@@ -0,0 +1,68 @@+"""AST test that `unsloth run` looks for the console script Windows actually ships.++The venv's entry point is `unsloth.exe` on Windows, so resolving the bare name made+`studio_bin.is_file()` false on every Windows install and aborted with "Unsloth venv+missing 'unsloth' entry point". Pinned by AST because reaching the assignment at+runtime means standing up a studio venv.+"""++from __future__ import annotations++import ast+from pathlib import Path++_STUDIO = Path(__file__).resolve().parents[2] / "unsloth_cli" / "commands" / "studio.py"+++def _run_function() -> ast.FunctionDef:+ tree = ast.parse(_STUDIO.read_text(encoding = "utf-8"))+ for node in tree.body:+ if isinstance(node, ast.FunctionDef) and node.name == "run":+ return node+ raise AssertionError("no top-level `run` command in unsloth_cli/commands/studio.py")+++def _studio_bin_value() -> ast.expr:+ for node in ast.walk(_run_function()):+ if not isinstance(node, ast.Assign):+ continue+ for target in node.targets:+ if (+ isinstance(target, ast.Name)+ and target.id == "studio_bin"+ and node.value is not None+ ):+ if not (isinstance(node.value, ast.Constant) and node.value.value is None):+ return node.value+ raise AssertionError("`run` never assigns a studio_bin path")+++def test_the_entry_point_name_is_chosen_per_platform():+ value = _studio_bin_value()+ assert isinstance(value, ast.BinOp) and isinstance(value.op, ast.Div), (+ "expected studio_bin to be built as `studio_python.parent / <name>`, got "+ f"{ast.dump(value)}"+ )+ names = {+ node.value+ for node in ast.walk(value.right)+ if isinstance(node, ast.Constant) and isinstance(node.value, str)+ }+ assert {+ "unsloth",+ "unsloth.exe",+ } <= names, f"studio_bin must pick between 'unsloth' and 'unsloth.exe'; got {sorted(names)}"+++def test_the_windows_branch_is_the_exe():+ """A swapped conditional would still hold the two names but break both platforms."""+ branch = next(+ node for node in ast.walk(_studio_bin_value().right) if isinstance(node, ast.IfExp)+ )+ assert isinstance(branch.body, ast.Constant) and branch.body.value == "unsloth.exe"+ assert isinstance(branch.orelse, ast.Constant) and branch.orelse.value == "unsloth"+ assert "Windows" in {+ node.value+ for node in ast.walk(branch.test)+ if isinstance(node, ast.Constant) and isinstance(node.value, str)+ }, "the .exe branch must be gated on platform.system() == 'Windows'"diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.pyindex 1498e777c66..6b85d42bc8b 100644--- a/unsloth_cli/commands/studio.py+++ b/unsloth_cli/commands/studio.py@@ -2137,8 +2137,12 @@ def run(if not studio_python:typer.echo("Unsloth Studio not set up. Run install.sh first.")raise typer.Exit(1)- # Re-exec via the studio venv's `unsloth` console-script.- studio_bin = studio_python.parent / "unsloth"+ # Re-exec via the studio venv's `unsloth` console-script. Windows ships it as+ # unsloth.exe, so the bare name is never a file there and `unsloth run` aborted+ # with "venv missing 'unsloth' entry point" on a perfectly good install.+ studio_bin = studio_python.parent / (+ "unsloth.exe" if platform.system() == "Windows" else "unsloth"+ )if not studio_bin.is_file():typer.echo("Unsloth venv missing 'unsloth' entry point. Re-run: unsloth studio setup")raise typer.Exit(1)