LykosAI/StabilityMatrix · error · FileNotFoundException

Venv python not found

Error message

Venv python not found

What it means

RunDetached — used by PipInstall, PipUninstall and CustomInstall — throws FileNotFoundException when the venv's PythonPath does not exist before launching the process. It means the virtual environment has no python interpreter, so no venv process can run.

Solutions

  1. Ensure the venv exists and is initialized (CreateAsync / SetupPyvenvCfg) before pip calls.
  2. Check File.Exists(PythonPath) beforehand and recreate the venv if missing.
  3. Recreate dangling symlinks by reinstalling the base Python version and recreating the venv.
  4. Verify BaseInstall.RootPath points to the intended venv directory.

Example fix

// before
await venv.PipInstall(new PipInstallParams { Packages = ["torch"] });
// after
if (!File.Exists(venv.PythonPath)) throw new FileNotFoundException("Recreate the venv", venv.PythonPath);
await venv.PipInstall(new PipInstallParams { Packages = ["torch"] });
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(venv.PythonPath)) {
    throw new InvalidOperationException($"Venv python missing at {venv.PythonPath}; recreate the venv");
}

Type guard

bool IsRunnable(PyVenvRunner v) => File.Exists(v.PythonPath);

Try / catch

try { await venv.PipInstall(params); }
catch (FileNotFoundException ex) { await RecreateVenvAsync(); await venv.PipInstall(params); }

Prevention

When it happens

Trigger: Calling PipInstall/PipUninstall/CustomInstall on a PyVenvRunner whose venv python binary is missing — venv not created yet, partially deleted, or PythonPath pointing at the wrong location.

Common situations: Calling pip methods before CreateAsync/InitializeAsync; venv directory deleted by user or cleaner tools; moving the venv without recreating it; base Python removed so venv python symlinks are dangling.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at StabilityMatrix.Core/Python/PyVenvRunner.cs:533

        );
        await process.WaitForExitAsync().ConfigureAwait(false);

        return new ProcessResult { ExitCode = process.ExitCode, StandardOutput = output.ToString() };
    }

    [MemberNotNull(nameof(Process))]
    public void RunDetached(
        ProcessArgs args,
        Action<ProcessOutput>? outputDataReceived,
        Action<int>? onExit = null,
        bool unbuffered = true
    )
    {
        var arguments = args.ToString();

        if (!PythonPath.Exists)
        {
            throw new FileNotFoundException("Venv python not found", PythonPath);
        }
        SetPyvenvCfg(BaseInstall.RootPath);

        Logger.Info(
            "Launching venv process [{PythonPath}] "
                + "in working directory [{WorkingDirectory}] with args {Arguments}",
            PythonPath,
            WorkingDirectory?.ToString(),
            arguments
        );

        var filteredOutput =
            outputDataReceived == null
                ? null
                : new Action<ProcessOutput>(s =>
                {
                    if (SuppressOutput.Any(s.Text.Contains))
                    {

View on GitHub (pinned to af93d6ef57)