{"record":{"id":"94be882144a845b9","repo":"LykosAI/StabilityMatrix","slug":"venv-python-not-found","errorCode":null,"errorMessage":"Venv python not found","messagePattern":"Venv python not found","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":533,"sourceCode":"        );\n        await process.WaitForExitAsync().ConfigureAwait(false);\n\n        return new ProcessResult { ExitCode = process.ExitCode, StandardOutput = output.ToString() };\n    }\n\n    [MemberNotNull(nameof(Process))]\n    public void RunDetached(\n        ProcessArgs args,\n        Action<ProcessOutput>? outputDataReceived,\n        Action<int>? onExit = null,\n        bool unbuffered = true\n    )\n    {\n        var arguments = args.ToString();\n\n        if (!PythonPath.Exists)\n        {\n            throw new FileNotFoundException(\"Venv python not found\", PythonPath);\n        }\n        SetPyvenvCfg(BaseInstall.RootPath);\n\n        Logger.Info(\n            \"Launching venv process [{PythonPath}] \"\n                + \"in working directory [{WorkingDirectory}] with args {Arguments}\",\n            PythonPath,\n            WorkingDirectory?.ToString(),\n            arguments\n        );\n\n        var filteredOutput =\n            outputDataReceived == null\n                ? null\n                : new Action<ProcessOutput>(s =>\n                {\n                    if (SuppressOutput.Any(s.Text.Contains))\n                    {","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L515-L551","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the venv exists and is initialized (CreateAsync / SetupPyvenvCfg) before pip calls.","Check File.Exists(PythonPath) beforehand and recreate the venv if missing.","Recreate dangling symlinks by reinstalling the base Python version and recreating the venv.","Verify BaseInstall.RootPath points to the intended venv directory."],"exampleFix":"// before\nawait venv.PipInstall(new PipInstallParams { Packages = [\"torch\"] });\n// after\nif (!File.Exists(venv.PythonPath)) throw new FileNotFoundException(\"Recreate the venv\", venv.PythonPath);\nawait venv.PipInstall(new PipInstallParams { Packages = [\"torch\"] });","handlingStrategy":"validation","validationCode":"if (!File.Exists(venv.PythonPath)) {\n    throw new InvalidOperationException($\"Venv python missing at {venv.PythonPath}; recreate the venv\");\n}","typeGuard":"bool IsRunnable(PyVenvRunner v) => File.Exists(v.PythonPath);","tryCatchPattern":"try { await venv.PipInstall(params); }\ncatch (FileNotFoundException ex) { await RecreateVenvAsync(); await venv.PipInstall(params); }","preventionTips":["Initialize venvs through the library's CreateAsync before any pip call","Guard every pip/RunDetached call with File.Exists(PythonPath)","Don't delete venv directories out from under live runners"],"tags":["python","venv","file-not-found","process-launch"],"backgroundTag":"file-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}