{"record":{"id":"23dcbf5438b525ad","repo":"LykosAI/StabilityMatrix","slug":"pyvenv-cfg-not-found","errorCode":null,"errorMessage":"pyvenv.cfg not found","messagePattern":"pyvenv\\.cfg not found","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyVenvRunner.cs","lineNumber":199,"sourceCode":"    /// <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)\n    {\n        // Skip if we are not created yet\n        if (!Exists())\n            return;\n\n        // Skip if already set to same value\n        if (lastSetPyvenvCfgPath == pythonDirectory && !force)\n            return;\n\n        // Path to pyvenv.cfg\n        var cfgPath = Path.Combine(RootPath, \"pyvenv.cfg\");\n        if (!File.Exists(cfgPath))\n        {\n            throw new FileNotFoundException(\"pyvenv.cfg not found\", cfgPath);\n        }\n\n        Logger.Info(\"Updating pyvenv.cfg with embedded Python directory {PyDir}\", pythonDirectory);\n\n        var baseExecutable = Path.Combine(\n            pythonDirectory,\n            Compat.IsWindows ? \"python.exe\" : RelativePythonPath\n        );\n\n        var cfg = PyVenvCfg.Load(cfgPath);\n        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;","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyVenvRunner.cs#L181-L217","documentation":"SetPyvenvCfg() throws FileNotFoundException when RootPath/pyvenv.cfg does not exist. It needs this file to rewrite the base (embedded) Python directory pointers after the base install moved. Called by PipList, PipShow, PipIndex, Run, and RunDetached, so any pip/run operation on a venv missing this marker file fails.","triggerScenarios":"Calling PipList/PipShow/PipIndex/Run/RunDetached on a PyVenvRunner whose RootPath does not contain pyvenv.cfg — i.e. Setup() was never completed on this directory, or the cfg file was deleted, or RootPath was repointed at a non-venv directory.","commonSituations":"RootPath set to an empty or wrong directory; venv creation failed midway leaving no pyvenv.cfg; user manually deleted pyvenv.cfg or copied a venv without it; calling Run* on a runner that was never Set up.","solutions":["Ensure Setup() completed successfully for this RootPath before calling pip/run methods.","Verify RootPath points at the venv root (the folder containing pyvenv.cfg), not a subdirectory.","Recreate the venv if pyvenv.cfg was deleted or the venv is corrupted.","Check Exists()/cfgPath on disk before invoking the operation."],"exampleFix":"// before\nawait venvRunner.PipInstall(args);\n// after\nif (!File.Exists(Path.Combine(venvRunner.RootPath, \"pyvenv.cfg\")))\n{\n    await venvRunner.Setup(null, null, ct);\n}\nawait venvRunner.PipInstall(args);","handlingStrategy":"validation","validationCode":"bool venvReady = File.Exists(Path.Combine(venvRunner.RootPath, \"pyvenv.cfg\"));\nif (!venvReady) throw new InvalidOperationException(\"Venv not initialized\");","typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) when (e.FileName?.Contains(\"pyvenv.cfg\") == true)\n{\n    // re-run Setup or surface 'environment not provisioned' to user\n}","preventionTips":["Run Setup() before any pip/run operations.","Never delete or manually edit pyvenv.cfg.","Re-point RootPath whenever the install directory moves."],"tags":["python","venv","file-not-found"],"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-16T04:17:20.429Z"}