|
1 | 1 | /*
|
2 | 2 | * This file is part of the Buildings and Habitats object Model (BHoM)
|
3 |
| - * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. |
| 3 | + * Copyright (c) 2015 - 2025, the respective contributors. All rights reserved. |
4 | 4 | *
|
5 | 5 | * Each contributor holds copyright over their respective contributions.
|
6 | 6 | * The project versioning (Git) records all such contribution source information.
|
@@ -89,7 +89,6 @@ public static string DownloadFile(
|
89 | 89 |
|
90 | 90 | /******************************************************/
|
91 | 91 |
|
92 |
| - [PreviousVersion("8.0", "BH.Engine.Python.Compute.DownloadPython(BH.oM.Python.Enums.PythonVersion, System.String)")] |
93 | 92 | [Description("Download and install a specified version of python, and return the executable for it.")]
|
94 | 93 | [Input("version", "The version of python to download.")]
|
95 | 94 | [Output("pythonExecutable", "The executable (python.exe) for the python version that was installed")]
|
@@ -133,8 +132,19 @@ public static string DownloadPythonVersion(this PythonVersion version)
|
133 | 132 | }
|
134 | 133 | }
|
135 | 134 |
|
136 |
| - return Path.Combine(basePath, "python.exe"); |
| 135 | + string pythonExePath = Path.Combine(basePath, "python.exe"); |
| 136 | + |
| 137 | + // It is possible for the installer to exit with ExitCode==0 without installing Python in the requested location. This can happen if the same version of Python appears to be installed elsewhere on the system. It can also happen if there was a 'dodgy' uninstall of a previous version. We've been unable to figure out where the installer is actually looking for existing installs. To fix dodgy uninstalls, run the installer again for the target version of Python (download links within EmbeddableURL.cs) and run a combination of 'repair' and 'uninstall' until it's gone. Installing the py launcher (via 'modify' in the installer) before attempting to uninstall could also help. |
| 138 | + |
| 139 | + if (!File.Exists(pythonExePath)) |
| 140 | + { |
| 141 | + BH.Engine.Base.Compute.RecordError($"The Python installer appears to have completed successfully, but \n{pythonExePath} does not exist. \nThis usually means that Python {version} already exists on your machine, but in a different location. \nThis toolkit is therefore unable to run any Python commands right now. \nTry uninstalling Python {version} from your system before running this BHoM method again."); |
| 142 | + return null; |
| 143 | + } |
| 144 | + |
| 145 | + return pythonExePath; |
137 | 146 | }
|
138 | 147 | }
|
139 | 148 | }
|
140 | 149 |
|
| 150 | + |
0 commit comments