<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Running Python Scripts from Add-In and Stand-alone Python Environments in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615036#M12909</link>
    <description>&lt;P&gt;ArcGIS Pro supports different python containers (see DeepLearning with ArcGIS Pro discussions re:&lt;SPAN&gt;&amp;nbsp;cloned environment of ArcGIS Pro's default environment,&lt;/SPAN&gt;).&amp;nbsp; The scripts would need to be explicitly told what container they should run in. Sounds like when you load a Raster the Spatial Analyst extension is being, for lack of a better word, Turned-On. This is (re)setting the &lt;STRONG&gt;_conda_&lt;/STRONG&gt; python path back to the default used by SA.&lt;/P&gt;&lt;P&gt;See -&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/guide/install-and-set-up/" target="_blank" rel="noopener"&gt;Install and Setup | ArcGIS API for Python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*&lt;SPAN&gt;By default, ArcGIS Pro has a single conda environment, arcgispro-py3, which includes all Python libraries used by ArcGIS Pro as well as several others, such as scipy and pandas. Enviornments can be activated in Pro via File | Package Manager.&amp;nbsp; I don't know how to do this in C#, but you need to replicate this Activated logic to swith between your Python scripts.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2025 15:50:40 GMT</pubDate>
    <dc:creator>RichardDaniels</dc:creator>
    <dc:date>2025-05-15T15:50:40Z</dc:date>
    <item>
      <title>Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1614589#M12903</link>
      <description>&lt;P class=""&gt;Hi,&lt;/P&gt;&lt;P class=""&gt;I’m hoping to get some insight or advice from the community on an issue we’re encountering with a custom ArcGIS Pro Add-in developed in C#.&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;Software Stack:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;ArcGIS Pro 3.2.4 (Advanced + Spatial Analyst)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Windows 10 Pro (Build 19045.5737)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Visual Studio 2022 (v17.13.6)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Python environments: arcgispro-py3 (default) and a separate standalone Python 3.9 installation (required for pygplates)&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;Objective&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;We have a custom Add-in button that runs &lt;STRONG&gt;two Python scripts in sequence:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P class=""&gt;Script 1 runs using the ArcGIS Pro environment (propy.bat).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Script 2 runs in an external standalone Python 3.9 environment (due to dependency conflicts with pygplates).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Script 1 runs again for some arcpy based clean up and other misc stuff.&lt;/P&gt;&lt;P class=""&gt;This all works well until the user manually adds a raster to the map (via &lt;EM&gt;Map → Add Data → Data). After doing this, the second script fails when executed via the standalone environment.&amp;nbsp; This is not the only thing that causes this problem - if the user opens up the interactive Python prompt in Pro - that causes the same issue.&lt;/EM&gt;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Symptoms&lt;/STRONG&gt;&lt;/H3&gt;&lt;P class=""&gt;After adding a raster in the Pro UI, attempts to run the tool again affects the external Python script fail with errors like:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Fatal &lt;SPAN class=""&gt;Python &lt;SPAN class=""&gt;error: &lt;SPAN class=""&gt;init_import_site: &lt;SPAN class=""&gt;Failed to &lt;SPAN class=""&gt;import the site &lt;SPAN class=""&gt;module ... &lt;SPAN class=""&gt;TypeError: &lt;SPAN class=""&gt;type &lt;SPAN class=""&gt;'types.GenericAlias' is not an acceptable base &lt;SPAN class=""&gt;type&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;If we run the same scripts from a standalone .NET Console app (i.e., not from within Pro), the scripts work perfectly, so I know it's nothing to do with scripts themselves.&amp;nbsp; The same scripts also work perfectly if run within a Python Toolbox - its only if the scripts are triggered from C# using the System.Diagnostics.Process instance.&lt;/P&gt;&lt;P class=""&gt;See code example below:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;public static string RunPythonScript(string scriptFileName, string[] scriptArguments, string pythonPath)
{
string scriptPath = Path.Combine(@"D:\Projects\FooProject\PythonScripts", scriptFileName);

if (!File.Exists(scriptPath))
return "Python script not found.";

if (string.IsNullOrWhiteSpace(pythonPath))
pythonPath = GetPythonPath();

if (string.IsNullOrWhiteSpace(pythonPath))
return "Python environment not found.";

var args = new StringBuilder($"\"{scriptPath}\"");
if (scriptArguments != null)
{
foreach (var arg in scriptArguments)
args.Append($" \"{arg}\"");
}

var startInfo = new ProcessStartInfo
{
FileName = pythonPath,
Arguments = args.ToString(),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};

using var process = new Process { StartInfo = startInfo };
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

return output;
}&lt;/LI-CODE&gt;&lt;H3&gt;&lt;STRONG&gt;Question to the Community&lt;/STRONG&gt;&lt;/H3&gt;&lt;P class=""&gt;Has anyone else encountered issues with the Pro environment interfering with external Python script execution from within a C# Add-in?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;Is there a known workaround for running Python scripts in multiple environments from a Pro Add-in?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Could Pro be “locking” or initializing some internal Python state that affects subprocesses? I appreciate this will probably be something to do with Conda and the internally installed Python environment Pro installs.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Is there a recommended pattern for isolating or sandboxing these environments in a Pro-based C# add-in workflow?&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;Why It Matters&lt;/STRONG&gt;&lt;/H3&gt;&lt;P class=""&gt;Our workflow depends on Python packages that cannot be installed in the default ArcGIS Pro environment (e.g., pygplates). Being able to reliably switch environments from a Pro Add-in is essential for our tool to function correctly and do the calculations we need to do with pygplates. Currently, interaction with the native Pro UI (like adding rasters) breaks that workflow and puts pro into some locked state with the default Python environment.&lt;/P&gt;&lt;P class=""&gt;Would appreciate any insights, workarounds, or confirmation if others have seen similar behavior.&lt;/P&gt;&lt;P class=""&gt;Thanks in advance!&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 14 May 2025 15:30:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1614589#M12903</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2025-05-14T15:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615036#M12909</link>
      <description>&lt;P&gt;ArcGIS Pro supports different python containers (see DeepLearning with ArcGIS Pro discussions re:&lt;SPAN&gt;&amp;nbsp;cloned environment of ArcGIS Pro's default environment,&lt;/SPAN&gt;).&amp;nbsp; The scripts would need to be explicitly told what container they should run in. Sounds like when you load a Raster the Spatial Analyst extension is being, for lack of a better word, Turned-On. This is (re)setting the &lt;STRONG&gt;_conda_&lt;/STRONG&gt; python path back to the default used by SA.&lt;/P&gt;&lt;P&gt;See -&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/latest/guide/install-and-set-up/" target="_blank" rel="noopener"&gt;Install and Setup | ArcGIS API for Python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*&lt;SPAN&gt;By default, ArcGIS Pro has a single conda environment, arcgispro-py3, which includes all Python libraries used by ArcGIS Pro as well as several others, such as scipy and pandas. Enviornments can be activated in Pro via File | Package Manager.&amp;nbsp; I don't know how to do this in C#, but you need to replicate this Activated logic to swith between your Python scripts.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 15:50:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615036#M12909</guid>
      <dc:creator>RichardDaniels</dc:creator>
      <dc:date>2025-05-15T15:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615194#M12911</link>
      <description>&lt;P&gt;Hi Richard, thanks for the answer - I will research the first part of your reply. However I think programmatically activating environments in Pro - would be problematic (even if its possible) as you have to restart Pro which would obviously disrupt the user experience and render the add-in unusable.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 20:28:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615194#M12911</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2025-05-15T20:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615237#M12912</link>
      <description>&lt;P&gt;Hi Vidar,&lt;/P&gt;&lt;P&gt;&amp;nbsp;could you try to modify your code to have `ProcessStartInfo` with `UseShellExecute=True` . Just curious if that has positive impact.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 22:33:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615237#M12912</guid>
      <dc:creator>GhislainPrince</dc:creator>
      <dc:date>2025-05-15T22:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615903#M12924</link>
      <description>&lt;P&gt;I will have a try - when I've uncorrupted my python environments with Pro.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 May 2025 09:14:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1615903#M12924</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2025-05-19T09:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1618802#M12955</link>
      <description>&lt;P&gt;HI - Yes I did try this but it didn't help - however I have changed tack and have worked how to leverage using a python toolbox from c# - and that seems to work much better.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 09:52:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1618802#M12955</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2025-05-28T09:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1673405#M13310</link>
      <description>&lt;P&gt;Did you ever find a solution to this? I have the same problem, and also found it was triggered by (in my case programmatically) adding a raster layer.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Dec 2025 19:34:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1673405#M13310</guid>
      <dc:creator>DanWalters</dc:creator>
      <dc:date>2025-12-16T19:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Running Python Scripts from Add-In and Stand-alone Python Environments</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1673561#M13313</link>
      <description>&lt;P&gt;I recommend running any python as a python toolbox and calling into your standalone python environments from there - but kick off the python toolbox using ExecuteToolAsync&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9383.html" target="_self"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9383.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This solved all my troubles. Yes you may have to redesign some of your code around a python toolbox - but it is better than using the Process command in C#.&amp;nbsp; This is the only solution I found to this problem.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2025 11:28:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-python-scripts-from-add-in-and-stand-alone/m-p/1673561#M13313</guid>
      <dc:creator>Vidar</dc:creator>
      <dc:date>2025-12-17T11:28:54Z</dc:date>
    </item>
  </channel>
</rss>

