<?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: Conda activate scripts are not executed within ArcGIS in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/conda-activate-scripts-are-not-executed-within/m-p/1338407#M68967</link>
    <description>&lt;P&gt;I haven't fully ingested your setup, that will take more attention time than I have at the moment as I try to solve my own challenge du jour, but one thing that comes to mind is perhaps `proswap.bat`? (found by way of&amp;nbsp;&lt;A href="https://samgeo.gishub.org/examples/arcgis/" target="_blank"&gt;https://samgeo.gishub.org/examples/arcgis/&lt;/A&gt;)&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2023 20:00:56 GMT</pubDate>
    <dc:creator>MattWilkie1</dc:creator>
    <dc:date>2023-10-16T20:00:56Z</dc:date>
    <item>
      <title>Conda activate scripts are not executed within ArcGIS</title>
      <link>https://community.esri.com/t5/python-questions/conda-activate-scripts-are-not-executed-within/m-p/1230529#M67802</link>
      <description>&lt;P&gt;Hello ESRI community,&lt;/P&gt;&lt;P&gt;I have run into an issue that I am unsure if it was an intentional design decision by ESRI or a bug.&amp;nbsp; The crux of the problem is that activation scripts placed in %CONDA_PREFIX/etc/conda/activate.d by conda packages (such as pdal, proj, and so on) are not being executed when python is started&amp;nbsp;&lt;EM&gt;within&lt;/EM&gt; ArcGIS pro.&amp;nbsp; Theses scripts are run are executed when starting the "Python Command Prompt".&lt;/P&gt;&lt;P&gt;Below I have an example with code to replicate.&amp;nbsp; I have intentionally avoided the process of cloning the conda environment that ArcGIS provides what is effectively a broken environment (seriously, try cloning the base environment and then conda install anything, it will take an eternity before telling you your environment has incompatible restraints).&lt;/P&gt;&lt;P&gt;In this example, I am using miniforge with mamba for the speed of the dependency solver; and I'm using PDAL as an example to highlight the lack of activation scripts being run.&amp;nbsp; This issue is not limited to PDAL, but to any package that ads an activation script to&amp;nbsp;%CONDA_PREFIX%\etc\conda\activate.d&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steps to replicate:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;SPAN class=""&gt;doscon&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&amp;gt; conda create -n arcgis-example -c esri python==3.7.11
&amp;gt; conda activate arcgis-example
&amp;gt; mamba install -c esri -c defaults numpy=1.20.1
&amp;gt; mamba install jinja2=2.11.3 &lt;/SPAN&gt;
&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;/SPAN&gt;

in &lt;SPAN class=""&gt;`envs/arcgis-example/conda-meta`&lt;/SPAN&gt; add a file named &lt;SPAN class=""&gt;`pinned`&lt;/SPAN&gt; with the following contents:

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;```&lt;/SPAN&gt;
&lt;SPAN class=""&gt;esri::python ==3.7.11
esri::numpy ==1.20.1
jinja ==2.11.3&lt;/SPAN&gt;
&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;BR /&gt;This is done to make sure that the next steps do not change versions of packages&lt;BR /&gt;to versions that are incompatible&lt;BR /&gt;
We then continue to make our conda environment arcgis compatible

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;SPAN class=""&gt;doscon&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&amp;gt; mamba install -c esri -c defaults arcpy arcgispro&lt;/SPAN&gt;
&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;/SPAN&gt;

The next process addresses some DLL conflicts I ran into with PDAL installed&lt;BR /&gt; from conda-forge

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;SPAN class=""&gt;docson&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&amp;gt; mamba install libzlib lerc=3.0=h0e60522_0 freetype==2.12.1=h546665d_0&lt;/SPAN&gt;
&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;/SPAN&gt;

Now we install PDAL.

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;SPAN class=""&gt;doscon&lt;/SPAN&gt;
&lt;SPAN class=""&gt;&amp;gt; mamba install pdal python-pdal&lt;/SPAN&gt;
&lt;SPAN class=""&gt;```&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;At this point, we fire up ArcGIS Pro, go to the Python manager and select the arcgis-example environment we recently created, and restart ArcGIS per the warning on the screen.&lt;/P&gt;&lt;P&gt;Now, we can open the python command prompt, and type: SET&lt;/P&gt;&lt;P&gt;There will be entries for PDAL_DRIVER_PATH, GDAL_DATA, GDAL_DRIVER_PATH, GEOTIFF_CSV, PROJ_LIB and so on.&lt;/P&gt;&lt;P&gt;Within ArcGIS Pro, start a Python Window and enter the following bit in there and run it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
for variable, value in os.environ.items():
    print(f"{variable}={value}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will notice that none of the variables that I mentioned above are present.&amp;nbsp; The contents of PATH are not quite the same either.&lt;/P&gt;&lt;P&gt;The source of the difference is due to the contents of %CONDA_PREFIX%/etc/conda/activate.d/*.bat not being executed when the Python interpreter within the ArcGIS is started, but it was run on the python command prompt.&lt;/P&gt;&lt;P&gt;The absence of properly activating the conda environment within ArcGIS can cause all sorts of problems for users which can be really difficult to troubleshoot, missing DLLs, etc etc.&lt;/P&gt;&lt;P&gt;A possible workaround would be to get the path to the activated conda environment, and update the variables explicitly in a toolkit file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import subprocess
import json

conda_json = json.loads(
    subprocess.run(
        ["conda", "info", "--json"], capture_output=True
    ).stdout
)
env_directory = conda_json["env_vars"]["CONDA_PREFIX"]
# update variables from here as most involve paths relative
# to the active conda environment
os.environ["PDAL_DRIVER_PATH"] = os.path.join(env_directory, "bin")
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This work-around would still not address issues in the python window within ArcGIS though and would be fragile to changes in dependencies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would love to know if there is something I am missing, please let me know!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ogi&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 17:25:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conda-activate-scripts-are-not-executed-within/m-p/1230529#M67802</guid>
      <dc:creator>OgnyanMoore</dc:creator>
      <dc:date>2022-11-10T17:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conda activate scripts are not executed within ArcGIS</title>
      <link>https://community.esri.com/t5/python-questions/conda-activate-scripts-are-not-executed-within/m-p/1338407#M68967</link>
      <description>&lt;P&gt;I haven't fully ingested your setup, that will take more attention time than I have at the moment as I try to solve my own challenge du jour, but one thing that comes to mind is perhaps `proswap.bat`? (found by way of&amp;nbsp;&lt;A href="https://samgeo.gishub.org/examples/arcgis/" target="_blank"&gt;https://samgeo.gishub.org/examples/arcgis/&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 20:00:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conda-activate-scripts-are-not-executed-within/m-p/1338407#M68967</guid>
      <dc:creator>MattWilkie1</dc:creator>
      <dc:date>2023-10-16T20:00:56Z</dc:date>
    </item>
  </channel>
</rss>

