From e1921720a268d592f8bc74d6184bf772a5266e0c Mon Sep 17 00:00:00 2001 From: Thomas Edward Kingstone Date: Wed, 11 Mar 2026 15:48:18 +0000 Subject: [PATCH 1/3] fix all subprocess runs by setting PYTHONHOME to empty string --- Python_Engine/Compute/Download.cs | 1 + Python_Engine/Compute/InstallPackage.cs | 5 ++++- Python_Engine/Compute/Remove.cs | 1 + Python_Engine/Compute/RequirementsTxt.cs | 2 ++ Python_Engine/Compute/Run.cs | 1 + Python_Engine/Compute/VirtualEnvironment.cs | 4 ++++ 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Python_Engine/Compute/Download.cs b/Python_Engine/Compute/Download.cs index 146b5b5..b50f94d 100644 --- a/Python_Engine/Compute/Download.cs +++ b/Python_Engine/Compute/Download.cs @@ -122,6 +122,7 @@ public static string DownloadPythonVersion(this PythonVersion version) } }) { + install.StartInfo.Environment["PYTHONHOME"] = ""; install.Start(); string stderr = install.StandardError.ReadToEnd(); install.WaitForExit(); diff --git a/Python_Engine/Compute/InstallPackage.cs b/Python_Engine/Compute/InstallPackage.cs index 7f9cf5b..7b7f0c9 100644 --- a/Python_Engine/Compute/InstallPackage.cs +++ b/Python_Engine/Compute/InstallPackage.cs @@ -59,9 +59,10 @@ List packages FileName = executable, Arguments = $"-m pip install --no-warn-script-location {packagesString}", UseShellExecute = false, - RedirectStandardError = true, + RedirectStandardError = true } }; + process.StartInfo.Environment["PYTHONHOME"] = ""; using (Process p = Process.Start(process.StartInfo)) { string standardError = p.StandardError.ReadToEnd(); @@ -111,6 +112,7 @@ string requirements RedirectStandardError = true, } }; + process.StartInfo.Environment["PYTHONHOME"] = ""; using (Process p = Process.Start(process.StartInfo)) { string standardError = p.StandardError.ReadToEnd(); @@ -155,6 +157,7 @@ string packageDirectory RedirectStandardError = true, } }; + process.StartInfo.Environment["PYTHONHOME"] = ""; using (Process p = Process.Start(process.StartInfo)) { string standardError = p.StandardError.ReadToEnd(); diff --git a/Python_Engine/Compute/Remove.cs b/Python_Engine/Compute/Remove.cs index fa5176d..aca0d76 100644 --- a/Python_Engine/Compute/Remove.cs +++ b/Python_Engine/Compute/Remove.cs @@ -109,6 +109,7 @@ public static void RemoveBaseVersion(PythonVersion version = PythonVersion.v3_10 } }) { + uninstall.StartInfo.Environment["PYTHONHOME"] = ""; uninstall.Start(); string stderr = uninstall.StandardError.ReadToEnd(); uninstall.WaitForExit(); diff --git a/Python_Engine/Compute/RequirementsTxt.cs b/Python_Engine/Compute/RequirementsTxt.cs index 26bee93..7084732 100644 --- a/Python_Engine/Compute/RequirementsTxt.cs +++ b/Python_Engine/Compute/RequirementsTxt.cs @@ -69,6 +69,8 @@ public static string RequirementsTxt( RedirectStandardOutput = true } }; + + process.StartInfo.Environment["PYTHONHOME"] = ""; using (Process p = Process.Start(process.StartInfo)) { StreamWriter sr = new StreamWriter(targetPath); diff --git a/Python_Engine/Compute/Run.cs b/Python_Engine/Compute/Run.cs index 589bcda..7340e69 100644 --- a/Python_Engine/Compute/Run.cs +++ b/Python_Engine/Compute/Run.cs @@ -52,6 +52,7 @@ public static string RunCommandStdout(string command, bool hideWindows = true, s process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; commandMode = "/C"; } + process.StartInfo.Environment["PYTHONHOME"] = ""; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; diff --git a/Python_Engine/Compute/VirtualEnvironment.cs b/Python_Engine/Compute/VirtualEnvironment.cs index d404a13..f9d4952 100644 --- a/Python_Engine/Compute/VirtualEnvironment.cs +++ b/Python_Engine/Compute/VirtualEnvironment.cs @@ -91,6 +91,8 @@ public static PythonEnvironment VirtualEnvironment(this PythonVersion version, s } }; + process.StartInfo.Environment["PYTHONHOME"] = ""; + using (Process p = Process.Start(process.StartInfo)) { string standardError = p.StandardError.ReadToEnd(); @@ -114,6 +116,8 @@ public static PythonEnvironment VirtualEnvironment(this PythonVersion version, s } }; + process.StartInfo.Environment["PYTHONHOME"] = ""; + using (Process p = Process.Start(process2.StartInfo)) { string standardError = p.StandardError.ReadToEnd(); From a795d90645b38140a1316741eb73d396a7751940 Mon Sep 17 00:00:00 2001 From: Thomas Edward Kingstone Date: Thu, 12 Mar 2026 12:57:22 +0000 Subject: [PATCH 2/3] (code compliance) rename InstallPackage.cs to Install.cs --- Python_Engine/Compute/{InstallPackage.cs => Install.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Python_Engine/Compute/{InstallPackage.cs => Install.cs} (100%) diff --git a/Python_Engine/Compute/InstallPackage.cs b/Python_Engine/Compute/Install.cs similarity index 100% rename from Python_Engine/Compute/InstallPackage.cs rename to Python_Engine/Compute/Install.cs From f1366b5c237b7924959d0e026d24fc94bf7decb1 Mon Sep 17 00:00:00 2001 From: Thomas Edward Kingstone Date: Thu, 12 Mar 2026 12:58:09 +0000 Subject: [PATCH 3/3] documentation compliance --- Python_Engine/Compute/Download.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python_Engine/Compute/Download.cs b/Python_Engine/Compute/Download.cs index b50f94d..054f03a 100644 --- a/Python_Engine/Compute/Download.cs +++ b/Python_Engine/Compute/Download.cs @@ -91,7 +91,7 @@ public static string DownloadFile( [Description("Download and install a specified version of python, and return the executable for it.")] [Input("version", "The version of python to download.")] - [Output("pythonExecutable", "The executable (python.exe) for the python version that was installed")] + [Output("pythonExecutable", "The executable (python.exe) for the python version that was installed.")] public static string DownloadPythonVersion(this PythonVersion version) { string url = version.EmbeddableURL();