{"record":{"id":"ea9ab3f96374de6a","repo":"LykosAI/StabilityMatrix","slug":"pip-show-failed-with-code-result-exitcode-result","errorCode":null,"errorMessage":"pip show failed with code {result.ExitCode}: {result.StandardOutput}, {result.StandardError}","messagePattern":"pip show failed with code (.+?): (.+?), (.+?)","errorType":"exception","errorClass":"ProcessException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":377,"sourceCode":"                EnvironmentVariables\n            )\n            .ConfigureAwait(false);\n\n        var packageNotFound =\n            result.StandardOutput?.Contains(\"Package(s) not found\", StringComparison.OrdinalIgnoreCase)\n                == true\n            || result.StandardError?.Contains(\"Package(s) not found\", StringComparison.OrdinalIgnoreCase)\n                == true;\n\n        if (packageNotFound)\n        {\n            return null;\n        }\n\n        // Check return code\n        if (result.ExitCode != 0)\n        {\n            throw new ProcessException(\n                $\"pip show failed with code {result.ExitCode}: {result.StandardOutput}, {result.StandardError}\"\n            );\n        }\n\n        if (string.IsNullOrWhiteSpace(result.StandardOutput))\n        {\n            throw new ProcessException(\n                $\"pip show returned no output for package '{packageName}': {result.StandardError}\"\n            );\n        }\n\n        return PipShowResult.Parse(result.StandardOutput);\n    }\n\n    /// <summary>\n    /// Run a pip index command, return result as PipIndexResult.\n    /// </summary>\n    public async Task<PipIndexResult?> PipIndex(","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L359-L395","documentation":"PipShow runs `pip show <package>` inside the venv and throws ProcessException when pip exits non-zero. It means pip itself failed to query the package (not merely that the package is missing). The message includes stdout and stderr so the caller can see pip's own diagnostic.","triggerScenarios":"Calling PyVenvRunner.PipShow(packageName) when the pip subprocess returns a non-zero exit code — e.g. package not found (exit 1), broken venv, corrupted pip metadata.","commonSituations":"Querying a package that is not installed in the venv; the venv's pip is broken or was deleted; site-packages was partially removed; package name misspelled.","solutions":["Check the stderr in the message: if it says 'Package(s) not found', call PipInstall for the package first or treat it as absent.","Run `pip show <package>` manually with the venv python (e.g. `venv/bin/python -m pip show <pkg>`) to reproduce.","Verify pip is intact: `venv/bin/python -m pip --version`; reinstall pip via `python -m ensurepip --upgrade` if broken.","Confirm the correct venv (BaseInstall.RootPath) is being targeted — a wrong venv lacks the package."],"exampleFix":"// before\nvar info = venv.PipShow(\"torch\");\n// after\nvar info = venv.PipShow(\"torch\"); // wrap in try-catch or pre-check:\n// if (await venv.PipInstallResult(new PipInstallParams { Packages = [\"torch\"] })) { ... }","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(venv.PipPath)) throw new InvalidOperationException(\"venv pip missing\");\nvar installed = await venv.PipList(); // pre-check membership instead of relying on PipShow","typeGuard":"bool HasPip(PyVenvRunner v) => File.Exists(v.PipPath);","tryCatchPattern":"try { var result = venv.PipShow(pkg); ... }\ncatch (ProcessException ex) when (ex.Message.Contains(\"not found\")) { /* treat package as absent */ }","preventionTips":["Pre-check package membership with PipList before PipShow","Wrap pip helpers in a resilient wrapper returning null on failure","Keep the venv's pip healthy and up to date"],"tags":["python","pip","subprocess","process-exception"],"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"}