LykosAI/StabilityMatrix · error · InvalidOperationException

torch is not installed in this environment. Install the…

Error message

torch is not installed in this environment. Install the Windows ROCm torch build first.

What it means

EnsureWindowsSdkDevelAsync validates a Windows ROCm Python environment before installing the ROCm SDK devel package. It runs pip show torch in the venv; if torch is not installed at all (PipShow returns null), it throws InvalidOperationException telling the user to install the Windows ROCm torch build first, because the SDK devel install logic depends on an existing torch build's version metadata.

Solutions

  1. Install the Windows ROCm torch build into the venv first (pip install torch --index-url https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/ or the appropriate multi-arch index)
  2. Run InstallWindowsNativeTorchAsync / the package helper's install flow before calling EnsureWindowsSdkDevelAsync
  3. Verify the venvRunner targets the intended Python environment (check venv path) and that pip show torch succeeds there
  4. Recreate the venv and re-run the full ROCm setup flow if the environment is inconsistent

Example fix

// before
await rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...); // torch missing
// after
if (await venvRunner.PipShow("torch") is null)
{
    await rocmHelper.InstallWindowsNativeTorchAsync(venvRunner, ...);
}
await rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (await venvRunner.PipShow("torch") is null)
{
    throw new InvalidOperationException("Install the Windows ROCm torch build first.");
}

Type guard

async Task<bool> HasTorchAsync(IPyVenvRunner venv) => await venv.PipShow("torch") is not null;

Try / catch

try { await rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("torch is not installed"))
{
    await rocmHelper.InstallWindowsNativeTorchAsync(venvRunner, ...);
}

Prevention

When it happens

Trigger: Calling EnsureWindowsSdkDevelAsync on a venv where torch was never installed, torch installation previously failed or was rolled back, or the venvRunner points at a different/empty Python environment than expected.

Common situations: Fresh venv created but the Windows ROCm torch wheel install step failed or was skipped; user manually deleted torch; wrong venv path configured so pip show runs against an unrelated environment.

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


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/b56aab4fcdcf22d6. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs:142

    /// Ensures <c>rocm-sdk-devel</c> is installed from the ROCm multi-arch index.
    /// It prefers a build whose date token matches the installed ROCm torch build and falls back to the latest available build when no exact match is available.
    /// </summary>
    public async Task EnsureWindowsSdkDevelAsync(
        IPyVenvRunner venvRunner,
        IProgress<ProgressReport>? progress = null,
        Action<ProcessOutput>? onConsoleOutput = null,
        CancellationToken cancellationToken = default
    )
    {
        var state = machineState.Value;
        var multiArchPythonPackageIndexUrl = WindowsRocmSupport.GetMultiArchPythonPackageIndexUrl(
            state.RuntimeGfxArch
        );

        var torchInfo = await venvRunner.PipShow("torch").ConfigureAwait(false);
        if (torchInfo is null)
        {
            throw new InvalidOperationException(
                "torch is not installed in this environment. Install the Windows ROCm torch build first."
            );
        }

        if (!IsUsableWindowsNativeTorchBuild(torchInfo.Version, null))
        {
            throw new InvalidOperationException(
                $"Installed torch is not a usable Windows ROCm build (detected version: {torchInfo.Version})."
            );
        }

        var nightlyBuildDateToken = TryGetNightlyBuildDateToken(torchInfo.Version);
        var installedRocmSdkDevel = await venvRunner.PipShow(RocmSdkDevelPackageName).ConfigureAwait(false);
        if (
            !string.IsNullOrWhiteSpace(nightlyBuildDateToken)
            && HasNightlyBuildDateToken(installedRocmSdkDevel?.Version, nightlyBuildDateToken)
        )
        {

View on GitHub (pinned to af93d6ef57)