Manage ArcGIS Pro Python Environments with Standalone Conda
For those of us who regularly work with Python and ArcGIS, especially for data science, life just got a lot easier with ArcGIS Pro 2.7. Now,
arcpy can be installed just like any other Conda package. This means ArcGIS Pro now can coexist on the same machine and play nicely with Conda (Anaconda or miniconda).
Prerequisites - ArcGIS Pro and Conda
To dive in, first get a Windows machine configured with Conda (Anaconda or miniconda) and ArcGIS Pro 2.7 installed. When installing, make sure and look for the option to, "Add Anaconda to my PATH environment variable," when installing Anaconda or similar for miniconda. At least with Anaconda, the default is not to do this. However, unless you already have a conda environment installed, this is what you want, and what you need for the rest of this tutorial to work.
If you already have ArcGIS Pro installed, when you open it up today, Thu 17 Dec 2020, it will prompt you to update. All you have to do is let it update to 2.7, and you will be good to go. If you don't have it already installed, you can get it from My.Esri.com.
Setting Up Your First ArcGIS Conda Environment
Next, open a command window as an administrator. This last part, as an administrator, is important. Creating this environment as an administrator will ensure you can update ArcGIS Pro without the
arcpy package breaking.
You can open a command prompt as an administrator by going to Start > Programs > Windows System, right clicking on Command Prompt, from the context menu selecting More, and finally selecting Run as administrator. Obvously, you have to be logged in using an account with administrative privilages to do this.
Now, from this command prompt window, you can set up a conda environment named
arcgis using the following commands.
> conda create --name arcgis python=3.7 > conda activate arcgis > conda install -c esri arcpy arcgis
I also strongly recommend installing
nodejs, so you can use the mapping widget in Jupyter Lab.
> conda install -c conda-forge nodejs
If you want to work with much of the deep learning functionality now included with ArcGIS Pro, there is a metapackage to ensure all the right packages and versions are included,
deep-learning-essentials. It is easily added with the following command.
> conda install -c esri deep-learning-essentials
If you want to see a walkthrough, this is the whole process in under eight mintes.
Now, you have everything available you normally would when working in ArcGIS Pro with Python, and you can add more packages from there. However, the real usefulness is in the abilty to create autonomous environments with different packages installed. This is why
environment.yml files are so useful.
YAML the Environment
This is where the real power of this paradigm becomes so useful. Rather than bore you with all the details of why, how and what not to do, here is a good reference if you want to dig deeper. Getting back to the task at hand, you can completely configure an environment just like the one above by creating the following text file called
environment.yml with little more than the following.
name: arcgis channels: - esri - conda-forge - defaults dependencies: - arcgis - arcpy - deep-learning-essentials - nodejs - python=3.7
Once created, all you now have to do is, from an administrator command prompt...
> conda env create -f environment.yml > conda activate arcgis
...and you have the same thing as before.
If you want a demonstration of all this, here is the whole process using an
Yes, I freely concede getting excited about how well Python and ArcGIS Pro now work together to make this all possible is more than just a little bit geeky. However, this is the environment I work in all day, every day, and also help clients to do this same thing. Now, with this ease of integration, life is much easier! Hence, yes, I am excited, and not embarassed to share the knowledge of how to take advantage of it. Have fun!