LykosAI/StabilityMatrix · error · FileNotFoundException
Python installation not found at
Error message
Python {version} installation not found at {installation.InstallPath} What it means
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.
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
Example fix
// before
await pyRunner.SwitchToInstallation(PyVersion.Parse("3.10.11")); // install deleted
// after
var install = await installationManager.GetInstallationAsync(PyVersion.Parse("3.10.11"));
if (!install.Exists())
await installationManager.SetupSharedRuntimeAsync(PyVersion.Parse("3.10.11"));
await pyRunner.SwitchToInstallation(PyVersion.Parse("3.10.11")); Defensive patterns
Strategy: validation
Validate before calling
var installation = await installationManager.GetInstallationAsync(version);
if (!Directory.Exists(installation.InstallPath))
await installationManager.SetupSharedRuntimeAsync(version); Try / catch
try
{
await pyRunner.SwitchToInstallation(version);
}
catch (FileNotFoundException ex)
{
logger.LogError(ex, "Python {Version} install missing; re-provisioning", version);
await installationManager.SetupSharedRuntimeAsync(version);
await pyRunner.SwitchToInstallation(version);
} Prevention
- Verify installation.Exists() before switching
- Re-download runtimes after cleaning app-data directories
- Pin to installed versions only; check availability first
When it happens
Trigger: 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.
Common situations: User removed or moved the Python install directory, shared-environment cleanup, a shared install being re-downloaded, requesting an old version after an upgrade.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Default Python installation not found at
- Python linked library not found
- get-pip not found
- pip not found
- pyvenv.cfg not found
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/cb2f360be538f64d.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Python/PyRunner.cs:169
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization",
true
);
Logger.Info("Shutting down previous Python runtime for version switch");
PythonEngine.Shutdown();
AppContext.SetSwitch(
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization",
false
);
}
// If not initialized or we had to shutdown, initialize with the new version
if (!PythonEngine.IsInitialized)
{
// Get the installation for this version
var installation = await installationManager.GetInstallationAsync(version).ConfigureAwait(false);
if (!installation.Exists())
{
throw new FileNotFoundException(
$"Python {version} installation not found at {installation.InstallPath}"
);
}
currentInstallation = installation;
// Initialize with this installation
await InitializeWithInstallation(installation).ConfigureAwait(false);
}
}
/// <summary>
/// Initialize Python runtime with a specific installation
/// </summary>
private async Task InitializeWithInstallation(PyInstallation installation)
{
if (PythonEngine.IsInitialized)
return;View on GitHub (pinned to af93d6ef57)