{"record":{"id":"0340d924d11573db","repo":"LykosAI/StabilityMatrix","slug":"pip-not-found-pyvenvrunner","errorCode":null,"errorMessage":"pip not found","messagePattern":"pip not found","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":228,"sourceCode":"        cfg[\"home\"] = pythonDirectory;\n        cfg[\"base-prefix\"] = pythonDirectory;\n        cfg[\"base-exec-prefix\"] = pythonDirectory;\n        cfg[\"base-executable\"] = baseExecutable;\n        cfg.Save(cfgPath);\n\n        // Update last set path\n        lastSetPyvenvCfgPath = pythonDirectory;\n    }\n\n    /// <summary>\n    /// Run a pip install command. Waits for the process to exit.\n    /// workingDirectory defaults to RootPath.\n    /// </summary>\n    public async Task PipInstall(ProcessArgs args, Action<ProcessOutput>? outputDataReceived = null)\n    {\n        if (!File.Exists(PipPath))\n        {\n            throw new FileNotFoundException(\"pip not found\", PipPath);\n        }\n\n        // Record output for errors\n        var output = new StringBuilder();\n\n        var outputAction = new Action<ProcessOutput>(s =>\n        {\n            Logger.Debug($\"Pip output: {s.Text}\");\n            // Record to output\n            output.Append(s.Text);\n            // Forward to callback\n            outputDataReceived?.Invoke(s);\n        });\n\n        RunDetached(args.Prepend(\"-m pip install\").Concat(\"--exists-action s\"), outputAction);\n        await Process.WaitForExitAsync().ConfigureAwait(false);\n\n        // Check return code","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L210-L246","documentation":"PipInstall() throws FileNotFoundException when the venv's pip executable (PipPath, e.g. Scripts/pip.exe or bin/pip) does not exist. The library will not spawn a pip command without a working pip inside the venv. Usually means the venv was created without pip or was never fully initialized.","triggerScenarios":"Calling PipInstall() on a venv created without pip (e.g. `python -m venv --without-pip`), a venv whose creation failed partway, or a PyVenvRunner whose RootPath/PythonPath configuration points to a venv lacking pip.","commonSituations":"Venv created with pip omitted; pip later uninstalled from the venv; corrupted/incomplete venv after failed setup or interrupted upgrade; wrong RootPath pointing to a non-venv folder.","solutions":["Recreate the venv via Setup() ensuring pip is included (no --without-pip).","Run `python -m ensurepip` against the venv interpreter to restore pip.","Verify PipPath exists before calling: File.Exists(venvRunner.PipPath).","Confirm RootPath and BaseInstall point at the intended, intact venv."],"exampleFix":"// before\nawait venvRunner.PipInstall(\"numpy\");\n// after\nif (!File.Exists(venvRunner.PipPath))\n{\n    await venvRunner.Setup(null, null, ct); // recreate venv with pip\n}\nawait venvRunner.PipInstall(\"numpy\");","handlingStrategy":"validation","validationCode":"if (!File.Exists(venvRunner.PipPath))\n{\n    await venvRunner.Setup(null, null, ct);\n}","typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) when (e.FileName == venvRunner.PipPath)\n{\n    // recreate venv, then retry the pip operation\n}","preventionTips":["Create venvs with pip included (never --without-pip).","Check PipPath existence as a preflight before batch pip operations.","Avoid uninstalling pip itself from the venv."],"tags":["python","pip","file-not-found"],"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"}