LykosAI/StabilityMatrix · error · InvalidOperationException
Torch is not installed in the virtual environment.
Error message
Torch is not installed in the virtual environment.
What it means
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.
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
Example fix
// before
await nunchakuStep.ExecuteAsync();
// after
if (await venv.GetPipPackageInfo("torch") is null) await torchInstallStep.ExecuteAsync();
await nunchakuStep.ExecuteAsync(); Defensive patterns
Strategy: validation
Validate before calling
var torch = await venv.GetPipPackageInfo("torch");
if (torch is null) await installTorchAsync(venv); Try / catch
try { await step.ExecuteAsync(progress); } catch (InvalidOperationException ex) when (ex.Message.Contains("Torch")) { await installTorchAsync(venv); await step.ExecuteAsync(progress); } Prevention
- Always install torch before accelerator add-ons
- Validate venv contents after package install
- Guard against users manually removing torch from venvs
When it happens
Trigger: Running the Nunchaku install step on a package venv where torch was never installed or was uninstalled, so pip query returns no torch package.
Common situations: Fresh package installs where torch install failed or was skipped; users who removed torch to save disk space; broken venvs.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- No compatible torch version found in the virtual…
- ComfyUI venv was not found at
- Windows ROCm bitsandbytes is only supported on Python 3.12.x
- Failed to start Forge Classic install process
- pyvenv.cfg is UTF-16 encoded; expected UTF-8/ASCII
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/f6281e7e3dac0ef6.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Models/PackageModification/InstallNunchakuStep.cs:60
venvDir,
workingDirectory: WorkingDirectory,
environmentVariables: EnvironmentVariables
);
var torchInfo = await venvRunner.PipShow("torch").ConfigureAwait(false);
var shortPythonVersionString = pyVersion.Minor switch
{
10 => "cp310",
11 => "cp311",
12 => "cp312",
13 => "cp313",
_ => throw new ArgumentOutOfRangeException("Invalid Python version"),
};
var platform = Compat.IsWindows ? "win_amd64" : "linux_x86_64";
if (torchInfo is null)
{
throw new InvalidOperationException("Torch is not installed in the virtual environment.");
}
var torchVersion = torchInfo.Version switch
{
var v when v.StartsWith("2.7") => "2.7",
var v when v.StartsWith("2.8") => "2.8",
var v when v.StartsWith("2.9") => "2.9",
var v when v.StartsWith("2.10") => "2.10",
_ => throw new InvalidOperationException(
"No compatible torch version found in the virtual environment."
),
};
var downloadUrl =
$"https://github.com/nunchaku-tech/nunchaku/releases/download/v1.0.2/nunchaku-1.0.2+torch{torchVersion}-{shortPythonVersionString}-{shortPythonVersionString}-{platform}.whl";
progress?.Report(
new ProgressReport(-1f, message: "Installing Nunchaku backend", isIndeterminate: true)
);View on GitHub (pinned to af93d6ef57)