{"record":{"id":"e50ff25f2d304d49","repo":"LykosAI/StabilityMatrix","slug":"venv-creation-failed-with-code-venvproc-exitcode","errorCode":null,"errorMessage":"Venv creation failed with code {venvProc.ExitCode}","messagePattern":"Venv creation failed with code (.+?)","errorType":"exception","errorClass":"ProcessException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":167,"sourceCode":"\n        // Create venv (copy mode if windows)\n        var args = new string[] { \"-m\", \"virtualenv\", Compat.IsWindows ? \"--always-copy\" : \"\", RootPath };\n\n        var venvProc = ProcessRunner.StartAnsiProcess(\n            BaseInstall.PythonExePath,\n            args,\n            WorkingDirectory?.FullPath,\n            onConsoleOutput\n        );\n\n        try\n        {\n            await venvProc.WaitForExitAsync(cancellationToken).ConfigureAwait(false);\n\n            // Check return code\n            if (venvProc.ExitCode != 0)\n            {\n                throw new ProcessException($\"Venv creation failed with code {venvProc.ExitCode}\");\n            }\n        }\n        catch (OperationCanceledException)\n        {\n            venvProc.CancelStreamReaders();\n        }\n        finally\n        {\n            venvProc.Kill();\n            venvProc.Dispose();\n        }\n    }\n\n    /// <summary>\n    /// Set current python path to pyvenv.cfg\n    /// This should be called before using the venv, in case user moves the venv directory.\n    /// </summary>\n    private void SetPyvenvCfg(string pythonDirectory, bool force = false)","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L149-L185","documentation":"Setup() launches `python -m venv` as a subprocess and throws ProcessException if the venv creation process exits with a non-zero exit code. This means the Python interpreter failed to build the virtual environment (bad interpreter, corrupted base install, disk/permission problems).","triggerScenarios":"Calling Setup() when the base Python executable is broken/incompatible (e.g. mismatched embedded Python version), the target disk is full, or antivirus blocks venv creation, causing the venv subprocess to return non-zero.","commonSituations":"Corrupted or half-deleted base Python install (BaseInstall path changed after upgrade); insufficient disk space; Windows file locks on python.exe from a previous process; embedded Python download incomplete.","solutions":["Inspect captured console output (onConsoleOutput) for the underlying Python error message.","Delete the partially created venv directory, re-download/reinstall the base Python (PyInstall), and retry Setup.","Verify the base Python executable runs standalone: `<basePython> --version`.","Free disk space and check no processes hold locks on the venv directory (Windows)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!File.Exists(baseInstall.PythonPath)) throw new InvalidOperationException(\"Base Python missing\");","typeGuard":null,"tryCatchPattern":"catch (ProcessException e)\n{\n    Logger.Error(\"venv creation failed: {Msg}\", e.Message);\n    await venvRunner.DeleteAsync(ct); // clean partial state\n    throw;\n}","preventionTips":["Verify the base Python install is complete before Setup (executable exists and runs).","Log onConsoleOutput so the underlying pip/python error is captured.","Ensure adequate free disk space before provisioning."],"tags":["python","venv","process","subprocess"],"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"}