Skip to content

Commit c449aac

Browse files
Fix grasshopper in rhino 8 failing to call python properly (#206)
2 parents 12843dc + f1366b5 commit c449aac

6 files changed

Lines changed: 14 additions & 2 deletions

File tree

Python_Engine/Compute/Download.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static string DownloadFile(
9191

9292
[Description("Download and install a specified version of python, and return the executable for it.")]
9393
[Input("version", "The version of python to download.")]
94-
[Output("pythonExecutable", "The executable (python.exe) for the python version that was installed")]
94+
[Output("pythonExecutable", "The executable (python.exe) for the python version that was installed.")]
9595
public static string DownloadPythonVersion(this PythonVersion version)
9696
{
9797
string url = version.EmbeddableURL();
@@ -122,6 +122,7 @@ public static string DownloadPythonVersion(this PythonVersion version)
122122
}
123123
})
124124
{
125+
install.StartInfo.Environment["PYTHONHOME"] = "";
125126
install.Start();
126127
string stderr = install.StandardError.ReadToEnd();
127128
install.WaitForExit();
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ List<string> packages
5959
FileName = executable,
6060
Arguments = $"-m pip install --no-warn-script-location {packagesString}",
6161
UseShellExecute = false,
62-
RedirectStandardError = true,
62+
RedirectStandardError = true
6363
}
6464
};
65+
process.StartInfo.Environment["PYTHONHOME"] = "";
6566
using (Process p = Process.Start(process.StartInfo))
6667
{
6768
string standardError = p.StandardError.ReadToEnd();
@@ -111,6 +112,7 @@ string requirements
111112
RedirectStandardError = true,
112113
}
113114
};
115+
process.StartInfo.Environment["PYTHONHOME"] = "";
114116
using (Process p = Process.Start(process.StartInfo))
115117
{
116118
string standardError = p.StandardError.ReadToEnd();
@@ -155,6 +157,7 @@ string packageDirectory
155157
RedirectStandardError = true,
156158
}
157159
};
160+
process.StartInfo.Environment["PYTHONHOME"] = "";
158161
using (Process p = Process.Start(process.StartInfo))
159162
{
160163
string standardError = p.StandardError.ReadToEnd();

Python_Engine/Compute/Remove.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public static void RemoveBaseVersion(PythonVersion version = PythonVersion.v3_10
109109
}
110110
})
111111
{
112+
uninstall.StartInfo.Environment["PYTHONHOME"] = "";
112113
uninstall.Start();
113114
string stderr = uninstall.StandardError.ReadToEnd();
114115
uninstall.WaitForExit();

Python_Engine/Compute/RequirementsTxt.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public static string RequirementsTxt(
6969
RedirectStandardOutput = true
7070
}
7171
};
72+
73+
process.StartInfo.Environment["PYTHONHOME"] = "";
7274
using (Process p = Process.Start(process.StartInfo))
7375
{
7476
StreamWriter sr = new StreamWriter(targetPath);

Python_Engine/Compute/Run.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static string RunCommandStdout(string command, bool hideWindows = true, s
5252
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
5353
commandMode = "/C";
5454
}
55+
process.StartInfo.Environment["PYTHONHOME"] = "";
5556
process.StartInfo.FileName = "cmd.exe";
5657
process.StartInfo.RedirectStandardOutput = true;
5758
process.StartInfo.RedirectStandardError = true;

Python_Engine/Compute/VirtualEnvironment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public static PythonEnvironment VirtualEnvironment(this PythonVersion version, s
9191
}
9292
};
9393

94+
process.StartInfo.Environment["PYTHONHOME"] = "";
95+
9496
using (Process p = Process.Start(process.StartInfo))
9597
{
9698
string standardError = p.StandardError.ReadToEnd();
@@ -114,6 +116,8 @@ public static PythonEnvironment VirtualEnvironment(this PythonVersion version, s
114116
}
115117
};
116118

119+
process.StartInfo.Environment["PYTHONHOME"] = "";
120+
117121
using (Process p = Process.Start(process2.StartInfo))
118122
{
119123
string standardError = p.StandardError.ReadToEnd();

0 commit comments

Comments
 (0)