{"record":{"id":"cb2f360be538f64d","repo":"LykosAI/StabilityMatrix","slug":"python-version-installation-not-found-at-installation","errorCode":null,"errorMessage":"Python {version} installation not found at {installation.InstallPath}","messagePattern":"Python (.+?) installation not found at (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PyRunner.cs","lineNumber":169,"sourceCode":"                \"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization\",\n                true\n            );\n            Logger.Info(\"Shutting down previous Python runtime for version switch\");\n            PythonEngine.Shutdown();\n            AppContext.SetSwitch(\n                \"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization\",\n                false\n            );\n        }\n\n        // If not initialized or we had to shutdown, initialize with the new version\n        if (!PythonEngine.IsInitialized)\n        {\n            // Get the installation for this version\n            var installation = await installationManager.GetInstallationAsync(version).ConfigureAwait(false);\n            if (!installation.Exists())\n            {\n                throw new FileNotFoundException(\n                    $\"Python {version} installation not found at {installation.InstallPath}\"\n                );\n            }\n\n            currentInstallation = installation;\n\n            // Initialize with this installation\n            await InitializeWithInstallation(installation).ConfigureAwait(false);\n        }\n    }\n\n    /// <summary>\n    /// Initialize Python runtime with a specific installation\n    /// </summary>\n    private async Task InitializeWithInstallation(PyInstallation installation)\n    {\n        if (PythonEngine.IsInitialized)\n            return;","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PyRunner.cs#L151-L187","documentation":"PyRunner.SwitchToInstallation looks up a Python installation for the requested version via the installation manager and verifies it exists on disk before switching. If the installation directory is missing, a FileNotFoundException is thrown naming the expected InstallPath.","triggerScenarios":"Calling SwitchToInstallation(version) when no CPython installation of that version exists at the expected path — e.g. after deleting the venv/python folder, or requesting a version that was never installed.","commonSituations":"User removed or moved the Python install directory, shared-environment cleanup, a shared install being re-downloaded, requesting an old version after an upgrade.","solutions":["Install the required Python version (let the installation manager download/set it up) before switching","Verify installation.InstallPath exists on disk before calling SwitchToInstallation","Use the default installation if an exact version is optional","Catch FileNotFoundException and trigger re-setup of the Python environment"],"exampleFix":"// before\nawait pyRunner.SwitchToInstallation(PyVersion.Parse(\"3.10.11\")); // install deleted\n// after\nvar install = await installationManager.GetInstallationAsync(PyVersion.Parse(\"3.10.11\"));\nif (!install.Exists())\n    await installationManager.SetupSharedRuntimeAsync(PyVersion.Parse(\"3.10.11\"));\nawait pyRunner.SwitchToInstallation(PyVersion.Parse(\"3.10.11\"));","handlingStrategy":"validation","validationCode":"var installation = await installationManager.GetInstallationAsync(version);\nif (!Directory.Exists(installation.InstallPath))\n    await installationManager.SetupSharedRuntimeAsync(version);","typeGuard":null,"tryCatchPattern":"try\n{\n    await pyRunner.SwitchToInstallation(version);\n}\ncatch (FileNotFoundException ex)\n{\n    logger.LogError(ex, \"Python {Version} install missing; re-provisioning\", version);\n    await installationManager.SetupSharedRuntimeAsync(version);\n    await pyRunner.SwitchToInstallation(version);\n}","preventionTips":["Verify installation.Exists() before switching","Re-download runtimes after cleaning app-data directories","Pin to installed versions only; check availability first"],"tags":["python","file-not-found","environment"],"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"}