Confluence Retirement

In an effort to consolidate USGS hosted Wikis, myUSGS’ Confluence service is scheduled for retirement on January 27th, 2023. The official USGS Wiki and collaboration space is now SharePoint. Please migrate existing spaces and content to the SharePoint platform and remove it from Confluence at your earliest convenience. If you need any additional information or have any concerns about this change, please contact myusgs@usgs.gov. Thank you for your prompt attention to this matter.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: New version of usercustomize.py

...

The critical modules for ArcGIS compatibility can be determined from your version of ArcGIS from the Desktop or Pro Python command line.

(Or you can just look at the list below under B.)

Code Block
languagepy
# pyversions.py - report critical python stack for use with ArcGIS
# example output:
# ArcGIS install folder: C:\Users\jwpowell>ArcGIS\Desktop10.4
# sys.executable: C:\Python27\ArcGIS10ArcGISx6410.24\pythonpythonw.exe -c ^
"import sys, numpy, matplotlib;print(sys.version, numpy
# matplotlib: 1.4.3
# numpy: 1.9.2
# scipy: 0.15.1
import sys
import os
ff = "{}: {}"
try:
    print("ArcGIS install folder: {}".format(os.environ["AGSDESKTOPJAVA"][:-1]))
    print(ff.format("sys.executable", sys.executable))
    import matplotlib
    print(ff.format("matplotlib", matplotlib.__version__))    
    import numpy
    print(ff.format("numpy", matplotlibnumpy.__version__)"
('2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]', '1.7.1', '1.3.0')
 )
    import scipy
    print(ff.format("scipy", scipy.__version__))
except:
    pass

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.

  1. Open the Anaconda prompt Type (depending on Arc version):32 or 64, depending on the ArcGIS environment you are integrating with)
  2. Create a compatible environment
    1. 32-bit (ArcMap, ArcCatalog)
      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"
    2. 64-bit (Background Geoprocessing (x64), ArcGIS Pro
      ArcGIS 10.x x64 background processing: (same as above, from 64 bit prompt, for example:
          "conda create -n arc105x64 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)
    1. "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):
    1. 3: "conda create -n arcpro13 python=3.4.4 numpy=1.10 matplotlib=1.4.3 scipy=0.16.1 pandas pyparsing xlrd xlwt"
      ArcGIS Pro 2.0: "conda create -n arcpro13 python=3.4.4 numpy=1.10 matplotlib=1.4.3 scipy=0.16.1 pandas pyparsing xlrd xlwt"
  3. 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.

...

  1. Install Anaconda, setup environment to match your ArcGIS version
  2. Download and edit the installation paths in this script (usercustomize.py.txt) to match your setup
  3. 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

    (open Anaconda prompt)
    > activate arc1041
    > python <path>\usercustomize.py
     
  4. Place the script in the Conda Python user your user site packages folder (with the name usercustomize with the name usercustomize.py)
    The user site-packages folder path can be found with:  python -m site --user-site
    Usually:  C:\Users\username\AppData\Roaming\Python\Python27\site-packages (ArcGIS Desktop)
           C:\Users\username\AppData\Roaming\Python\Python34\site-packages (ArcGIS Pro, Python35 for Pro 2.0)

Testing and Troubleshooting

ArcGIS

  1. Start ArcMapDesktop or Pro, open the Python window
  2. import pandas (or other module you've added to your Anaconda / ArcGIS virtual environment)
  3. print
    print ("\n".join(sys.path))  -- you should see the Anaconda site-packages near the end of the list

 Anaconda

  1. Start Anaconda command prompt, activate your ArcGIS environment
  2. import arcpy
  3. print 32-bit or 64-bit  command prompt
  4. activate arc1041 # or whatever appropriate environment you've set up
  5. print ("\n".join(sys.path))  -- you should see
    the arcpy
     ArcGIS site-packages in the list
  6. import arcpy

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.

To modify the python 'stack' for your ArcGIS-friendly virtual environment:

  1. Open Anaconda Command Prompt (via the Start menu on Windows, e.g.)
  2. conda install -n arc101 python=2.7.5 matplotlib=1.3.0 numpy=1.6.1 pandas=0.10.0

...