{"record":{"id":"65db71be6664ddfe","repo":"LykosAI/StabilityMatrix","slug":"pip-list-failed-with-code-result-exitcode-result","errorCode":null,"errorMessage":"pip list failed with code {result.ExitCode}: {result.StandardOutput}, {result.StandardError}","messagePattern":"pip list failed with code (.+?): (.+?), (.+?)","errorType":"exception","errorClass":"ProcessException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":314,"sourceCode":"        {\n            throw new FileNotFoundException(\"pip not found\", PipPath);\n        }\n\n        SetPyvenvCfg(BaseInstall.RootPath);\n\n        var result = await ProcessRunner\n            .GetProcessResultAsync(\n                PythonPath,\n                \"-m pip list --format=json\",\n                WorkingDirectory?.FullPath,\n                EnvironmentVariables\n            )\n            .ConfigureAwait(false);\n\n        // Check return code\n        if (result.ExitCode != 0)\n        {\n            throw new ProcessException(\n                $\"pip list failed with code {result.ExitCode}: {result.StandardOutput}, {result.StandardError}\"\n            );\n        }\n\n        // There may be warning lines before the Json line, or update messages after\n        // Filter to find the first line that starts with [\n        var jsonLine = result\n            .StandardOutput?.SplitLines(\n                StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries\n            )\n            .Select(line => line.Trim())\n            .FirstOrDefault(line =>\n                line.StartsWith(\"[\", StringComparison.OrdinalIgnoreCase)\n                && line.EndsWith(\"]\", StringComparison.OrdinalIgnoreCase)\n            );\n\n        if (jsonLine is null)\n        {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L296-L332","documentation":"PipList() throws ProcessException when `pip list --format=json` exits non-zero, embedding exit code, stdout, and stderr in the message. Pip's JSON output is then filtered to the first line starting with '[' to strip warnings/update banners.","triggerScenarios":"pip list failing due to corrupted site-packages metadata (unreadable dist-info), broken pip installation inside the venv, or environment issues causing pip itself to crash on startup.","commonSituations":"Corrupted package metadata from interrupted installs; pip upgraded/broken mid-flight; mismatched base-interpreter after embedded Python update so pip's vendored imports fail.","solutions":["Inspect stdout/stderr in the exception message for pip's traceback.","Reinstall/repair pip in the venv (`python -m ensurepip --upgrade` or reinstall pip wheel).","Remove corrupted dist-info directories in venv site-packages if a specific package's metadata is at fault.","Recreate the venv if the environment is systematically broken."],"exampleFix":"// before\nvar packages = await venvRunner.PipList();\n// after\nIReadOnlyList<PipPackageInfo> packages;\ntry\n{\n    packages = await venvRunner.PipList();\n}\ncatch (ProcessException e)\n{\n    Logger.Warning(\"pip list failed, assuming empty: {Msg}\", e.Message);\n    packages = Array.Empty<PipPackageInfo>();\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"List<PipPackageInfo> packages;\ntry\n{\n    packages = (List<PipPackageInfo>)await venvRunner.PipList();\n}\ncatch (ProcessException e)\n{\n    Logger.Warning(\"pip list unavailable: {Msg}\", e.Message);\n    packages = new List<PipPackageInfo>(); // empty fallback\n}","preventionTips":["Keep pip healthy: repair via ensurepip if pip itself errors.","Watch for corrupted dist-info after interrupted installs and clean them up.","Recreate the venv after base Python version changes."],"tags":["python","pip","process","json"],"backgroundTag":"command-not-found","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"}