diff --git a/src/Libraries/DSCPython/CPythonEvaluator.cs b/src/Libraries/DSCPython/CPythonEvaluator.cs index a2072844833..353e6a698f0 100644 --- a/src/Libraries/DSCPython/CPythonEvaluator.cs +++ b/src/Libraries/DSCPython/CPythonEvaluator.cs @@ -178,7 +178,7 @@ public static object EvaluatePythonScript( return null; } - Python.Included.Installer.SetupPython().Wait(); + InstallPython(); if (!PythonEngine.IsInitialized) { @@ -246,6 +246,21 @@ public static object EvaluatePythonScript( } } + private static bool isPythonInstalled = false; + /// + /// Makes sure Python is installed on the system and it's location added to the path. + /// NOTE: Calling SetupPython multiple times will add the install location to the path many times, + /// potentially causing the environment variable to overflow. + /// + private static void InstallPython() + { + if (!isPythonInstalled) + { + Python.Included.Installer.SetupPython().Wait(); + isPythonInstalled = true; + } + } + /// /// Creates and initializaes the global Python scope. /// diff --git a/src/PythonMigrationViewExtension/MigrationAssistant/ScriptMigrator.cs b/src/PythonMigrationViewExtension/MigrationAssistant/ScriptMigrator.cs index 696a43146ae..3625b59e716 100644 --- a/src/PythonMigrationViewExtension/MigrationAssistant/ScriptMigrator.cs +++ b/src/PythonMigrationViewExtension/MigrationAssistant/ScriptMigrator.cs @@ -19,7 +19,7 @@ internal static class ScriptMigrator /// internal static string MigrateCode(string code) { - Installer.SetupPython().Wait(); + InstallPython(); if (!PythonEngine.IsInitialized) { @@ -70,6 +70,21 @@ internal static string MigrateCode(string code) } } + private static bool isPythonInstalled = false; + /// + /// Makes sure Python is installed on the system and it's location added to the path. + /// NOTE: Calling SetupPython multiple times will add the install location to the path many times, + /// potentially causing the environment variable to overflow. + /// + private static void InstallPython() + { + if (!isPythonInstalled) + { + Installer.SetupPython().Wait(); + isPythonInstalled = true; + } + } + private static string Get2To3MigrationScript(Assembly asm) { return GetEmbeddedScript(asm, "Dynamo.PythonMigration.MigrationAssistant.migrate_2to3.py");