What is the Anaconda distribution?
Anaconda is an open-source Python distribution that makes is possible to easily install and manage many pre-packaged third party Python modules.
It has some big advantages over using the Python Esri provides with ArcGIS:
- Very useful tools not in Esri's standard distribution are available (IPython, Jupyter notebook, Spyder)
- You can install and update the Python stack as a regular (non-pr) user
- You can install and remove, and update third party packages easily, with Anaconda checking for compatibility for you
- Manage multiple environments (for example, one compatible with ArcMap, another compatible with ArcGIS Pro)
The general workflow to make this happen is to:
- Install Anaconda without fouling the Windows environment (paths, registry) to break Esri's python stack
- Configure Anaconda with the particular add-ons you want, and
- Configure ArcGIS's Python so that it is aware of the Anaconda environment (so you can import modules not in Esri's stack)
1) Download and Install Anaconda
The main distribution is pretty large. MiniConda downloads what you need to do to start. Choose the Miniconda that matches the main software you want to integrate with. (You can install both if you want.)
Run the .exe installers
Select install for a single user (Not "All Users")
- Install to a folder where there is going to be plenty of space (recommend the D drive, not the C drive)
- IMPORTANT: To avoid breaking ArcGIS, uncheck the checkboxes (a) make Anaconda the default Python and (b) add Anaconda's Python to the PATH.
- Here are screenshots to help guide you through the install process.
Anaconda first run
Open the Anaconda prompt window (Search in Windows and start the shortcut "Anaconda Prompt") and enter "python"
Python 2.7.13 |Continuum Analytics, Inc.| (default, May 11 2017, 14:07:41) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
At this point, you have a nice Anaconda Python setup (~ 225 MB) that's spiffy and new and totally useless with ArcMap.
2) Set up an SSL certificate (USGS instructions) for Conda
DOI is now requiring SSL encryption. Without the setup below you will likely get a error that SSL certificates are not valid. The following steps will get you set up to use SSL so Conda will work:
- Download the DOI certificate: https://internal.usgs.gov/oei/wp-content/itsec/DOIRootCA2.cer to your Downloads folder
- Open "Anaconda Prompt" window
- Set up the certificate to use it with Conda
copy %USERPROFILE%\Downloads\DOIRootCA.crt %USERPROFILE%\.certificates
conda config --set ssl_verify %USERPROFILE%\.certificates\DOIRootCA.crt
3) Configure Anaconda To Work with ArcGIS
The following workflow will demonstrate how set up a custom Python environment within Anaconda that has the same modules installed as ArcGIS Python, and then add a compatible version of Jupyter notebook.
The following example is for ArcGIS 10.4.1, assuming you have successfully installed MiniConda 2 32-bit (as above).
A. Find the versions of numpy and matplotlib for your version of ArcGIS Desktop
The critical modules for ArcGIS compatibility can be determined from your version of ArcGIS from the command line.
(Or you can just look at the list below under B.)
C:\Users\jwpowell> C:\Python27\ArcGIS10.2\python.exe -c ^
"import sys, numpy, matplotlib;print(sys.version, numpy.__version__, matplotlib.__version__)"
('2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]', '1.7.1', '1.3.0')
B. Create an Anaconda environment for use with ArcGIS
We'll also include a few other modules that we know are shipped in the ArcGIS Python stack.
- Open the Anaconda prompt
- Type (depending on Arc version):
ArcGIS 10.2.2: "conda create -n arc1022 python=2.7.5 numpy=1.7.1 matplotlib=1.3.0 pyparsing xlrd xlwt"
ArcGIS 10.3.1: "conda create -n arc1031 python=2.7.8 numpy=1.7.1 matplotlib=1.3.0 pyparsing xlrd xlwt"
ArcGIS 10.4.1: "conda create -n arc1041 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 scipy=0.16.0 pandas pyparsing xlrd xlwt"
ArcGIS 10.5: "conda create -n arc105 python=2.7.12 numpy=1.9.2 matplotlib=1.4.3 scipy=0.17.0 pandas pyparsing xlrd xlwt"
ArcGIS Pro 1.2 (x64): "conda create -n arcpro12 python=3.4.3 numpy=1.9.3 matplotlib=1.4.3 scipy=0.16.0 pandas pyparsing xlrd xlwt"
ArcGIS Pro 1.3 (x64): "conda create -n arcpro13 python=3.4.4 numpy=1.10 matplotlib=1.4.3 scipy=0.16.1 pandas pyparsing xlrd xlwt"
- The conda tool will:
- Determine that the specified package versions are compatible with each other.
- Find any packages on which these depend and determine most recent versions that are compatible with what you've asked for, if not completely specified.
- Show you what it plans to do and prompts you to continue.
- Download (only) the packages you need to "overlay" onto the base environment to get the environment you have specified.
- Set up a environment subdirectory, (D:\Users\cprice\Miniconda2\envs\arc1041 in our example) installing the downloaded packages into it. This adds up to about 1.5 GB in our ArcGIS 10.4.1 example.
C. Test the virtual environment
Open an Anaconda command window and load the virtual environment.
C:\Users\cprice> conda info --envs
# conda environments:
root * D:\Users\cprice\Miniconda2
Activating environment "arc1041"...
[arc1022] D:\Users\cprice> conda list
# packages in environment at D:\Users\cprice\Miniconda2\envs\arc1041:
dateutil 2.4.1 py27_0
matplotlib 1.3.0 np17py27_0
numpy 1.7.1 py27_3
D. Add more packages
You can add more packages using conda install, but make sure you specify version numbers for these that won't change the environment's version of python or numpy (or ArcGIS will not be able to use that environment anymore).
Let's add the Jupyter notebook and the Spyder IDE which are both popular additions to your toolbox.
Specifying python, numpy, and matplotlib versions makes sure the environment will still work with ArcGIS, and Anaconda determines the most recent compatible version of pandas (in our case, 0.13.0).
set ARCLIST=python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 scipy=0.16.0 pandas pyparsing xlrd xlwt
conda install -n arc1041 %ARCLIST% jupyter spyder
The following NEW packages will be INSTALLED:
You can search for more packages available in conda with conda search.
You're not limited to adding only packages to which conda has access to your new environment. Here's an example on how to install a commonly desired GIS-related package (shapely) into a conda virtual environment using the python pip utility:
3) Configure ArcGIS python to see Anaconda environment and vice versa
This can most easily be done (personal opinion) with a Python usercustomize.py startup script
- Install Anaconda, setup environment to match your ArcGIS version
- Download and edit the installation paths in this script (usercustomize.py.txt) to match your setup
- IMPORTANT - Test and debug this script by running it from python.exe for each of your environments, for example:
> C:\Python27\ArcGIS10.4\python.exe <path>\usercustomize.py
> activate arc1041
> python <path>\usercustomize.py
- Place the script in the Conda Python user site packages folder (with the name usercustomize.py)
The user site-packages folder path can be found with:
python -m site --user-site
Testing and Troubleshooting
- Start ArcMap, open the Python window
- import pandas (or other module you've added to your Anaconda / ArcGIS virtual environment)
- print ("\n".join(sys.path)) -- you should see the Anaconda site-packages near the end of the list
- Start Anaconda command prompt, activate your ArcGIS environment
- import arcpy
- print ("\n".join(sys.path)) -- you should see the arcpy site-packages in the list
If you get an error message when you try to import, a common cause is version incompatibilities between Esri's python environment modules and the conda modules. (Condo takes care of compatibility across its environment, but it can't know about versions Esri uses in their python install.) In the pandas example, version 0.10.1 also appears to use the same 1.6.1 version of numpy used by ArcGIS 10.1.x, but some errors occur when trying to import pandas due to some other incompatibility. The solution was to modify the Anaconda environment to use an older version of pandas (0.10.0). The other critical packages are included to avoid having Anaconda install some other incompatible packages.
- Open Anaconda Command Prompt (via the Start menu on Windows, e.g.)
conda install -n arc101 python=2.7.5 matplotlib=1.3.0 numpy=1.6.1
How to do a separate Python installation with ArcGIS? (GIS Stack Exchange)
Using ArcPy with Anaconda (PyMorton)