{"record":{"id":"f6281e7e3dac0ef6","repo":"LykosAI/StabilityMatrix","slug":"torch-is-not-installed-in-the-virtual-environment","errorCode":null,"errorMessage":"Torch is not installed in the virtual environment.","messagePattern":"Torch is not installed in the virtual environment\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/PackageModification/InstallNunchakuStep.cs","lineNumber":60,"sourceCode":"            venvDir,\n            workingDirectory: WorkingDirectory,\n            environmentVariables: EnvironmentVariables\n        );\n\n        var torchInfo = await venvRunner.PipShow(\"torch\").ConfigureAwait(false);\n        var shortPythonVersionString = pyVersion.Minor switch\n        {\n            10 => \"cp310\",\n            11 => \"cp311\",\n            12 => \"cp312\",\n            13 => \"cp313\",\n            _ => throw new ArgumentOutOfRangeException(\"Invalid Python version\"),\n        };\n        var platform = Compat.IsWindows ? \"win_amd64\" : \"linux_x86_64\";\n\n        if (torchInfo is null)\n        {\n            throw new InvalidOperationException(\"Torch is not installed in the virtual environment.\");\n        }\n\n        var torchVersion = torchInfo.Version switch\n        {\n            var v when v.StartsWith(\"2.7\") => \"2.7\",\n            var v when v.StartsWith(\"2.8\") => \"2.8\",\n            var v when v.StartsWith(\"2.9\") => \"2.9\",\n            var v when v.StartsWith(\"2.10\") => \"2.10\",\n            _ => throw new InvalidOperationException(\n                \"No compatible torch version found in the virtual environment.\"\n            ),\n        };\n\n        var downloadUrl =\n            $\"https://github.com/nunchaku-tech/nunchaku/releases/download/v1.0.2/nunchaku-1.0.2+torch{torchVersion}-{shortPythonVersionString}-{shortPythonVersionString}-{platform}.whl\";\n        progress?.Report(\n            new ProgressReport(-1f, message: \"Installing Nunchaku backend\", isIndeterminate: true)\n        );","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/PackageModification/InstallNunchakuStep.cs#L42-L78","documentation":"InstallNunchakuStep.ExecuteAsync queries the package's venv for torch metadata to pick a matching Nunchaku wheel; if torch is not installed, torchInfo is null and InvalidOperationException is thrown.","triggerScenarios":"Running the Nunchaku install step on a package venv where torch was never installed or was uninstalled, so pip query returns no torch package.","commonSituations":"Fresh package installs where torch install failed or was skipped; users who removed torch to save disk space; broken venvs.","solutions":["Install torch into the package venv before running the Nunchaku step","Reinstall/repair the package so its venv includes torch","Verify with pip list inside the venv that torch is present before installing Nunchaku"],"exampleFix":"// before\nawait nunchakuStep.ExecuteAsync();\n// after\nif (await venv.GetPipPackageInfo(\"torch\") is null) await torchInstallStep.ExecuteAsync();\nawait nunchakuStep.ExecuteAsync();","handlingStrategy":"validation","validationCode":"var torch = await venv.GetPipPackageInfo(\"torch\");\nif (torch is null) await installTorchAsync(venv);","typeGuard":null,"tryCatchPattern":"try { await step.ExecuteAsync(progress); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Torch\")) { await installTorchAsync(venv); await step.ExecuteAsync(progress); }","preventionTips":["Always install torch before accelerator add-ons","Validate venv contents after package install","Guard against users manually removing torch from venvs"],"tags":["csharp","python","venv","torch"],"backgroundTag":"missing-dependency","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}