Monthly Archives: July 2016

Setting up Anaconda, PySAL with ArcGIS Python environment

This tutorial shows you how to set up conda environment to work with ArcGIS 10.4 and ArcGIS Pro 1.3. You can download a pdf copy of the tutorial with screenshots HERE. At the 2016 Esri International User Conference in San Diego last month, Esri released ArcGIS Pro 1.3, which can now use conda for packaging Python libraries. This allows support of python under multiple Python environments. You no longer need to install a separate Python install to get the full Python capability with ArcGIS as you did with past versions.

Workflow to set up Anaconda with ArcGIS 10.4

  • 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 appropriate Anaconda content.

1) Install Anaconda for All Users

  1. Go to http://continuum.io/downloads
  2. Download the 32-bit version of Anaconda (Python 2.7)
  3. In the install dialogs:
    • Select install for All Users
    • conda01
    • Install to a folder by default (C:\Anaconda2)
    • conda02
    • IMPORTANT: To avoid breaking ArcGIS (or other software), uncheck the checkboxes (a) make Anaconda the default Python and (b) add Anaconda’s Python to the PATH.
    • conda03
  4. Go to Start > All Programs(apps) > Anaconda2(32-bit) > Anaconda Prompt. Right click, run as administrator

2) Configure an Anaconda environment for use with ArcGIS

  1. Find the versions of numpy and matplotlib ArcGIS is using.

Open ArcMap and its Python window, and enter these commands:

    • >>> import sys, numpy, matplotlib
    • >>> print(sys.version, numpy.__version__, matplotlib.__version__)
    • (‘2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]’, ‘1.9.2’, ‘1.4.3’)
    • conda04
  1. Create an Anaconda environment that is compatible with ArcGIS
    • Get to the Anaconda Command Prompt (Start > All Programs(apps) > Anaconda2(32-bit), pick “Anaconda Prompt“), Right click, Run as Administrator.
    • Type (depending on ArcGIS version, I am using ArcGIS 10.4 as an example here):
    • “conda create -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pyparsing xlrd xlwt pandas scipy ipython ipython-notebook ipython-qtconsole”
    • conda05
    • Enter y to proceed.
    • Anaconda’s conda command will then set up an environment subdirectory, ex: ” C:\Anaconda2\envs\arc104 “, installing the downloaded packages into it.
    • conda06
  2. Test the virtual environment
    • At the Anaconda Command Prompt, type: activate arc104
    • Type: conda list. You can see the list of packages installed.conda07
  3. 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 Python Spatial Analysis Library (pysal) module.
    • Type the following command at the Anaconda Prompt:”conda install -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pysal”
    • conda08

3) Configure ArcGIS to see Anaconda and vice versa

  1. Anaconda Python to ArcPy
    • Copy the Desktop10.4.pth file to the Anaconda environment site-packages folder:
    • From: C:\Python27\ArcGIS10.4\Lib\site-packages\Desktop10.4.pth
    • To: C:\Anaconda2\envs\arc104\Lib\site-packages\Desktop10.4.pth
  2. Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content “C:\Anaconda\envs\arc104\lib\site-packages” in it.
    • Then copy zconda.pth to C:\Python27\ArcGIS10.4\Lib\site-packages
  3. Testing in ArcMap
    • As a regular user, start ArcMap, open the Python window
    • type “import pysal”
    • type “pysal.” A popup menu with a list of pysal-provided functions is a pretty good sign the installation succeeded.
    • conda09
  4. Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arc104\python.exe
    • conda10
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arc104 environment.
    • conda11

Workflow to set up Anaconda with ArcGIS Pro 1.3

1) Create an Anaconda environment that is compatible with ArcGIS Pro

  • Copy the folder arcgispro-py3 from C:\Program Files\ArcGIS\Pro\bin\Python\envs and paste to C:\Anaconda2\envs
  • Rename the copied folder arcgispro-py3 in C:\Anaconda2\envs to arcpro

2) Test the virtual environment

  • At the Anaconda Command Prompt, type: activate arcpro
  • Type: conda list. You can see the list of packages installed

3) Add more packages

  • Let’s add the Python Spatial Analysis Library (pysal) module.
  • Type the following command at the Anaconda Prompt:”conda install pysal”

4) Configure ArcGIS to see Anaconda and vice versa

  • Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content “C:\Anaconda2\envs\arcpro\lib\site-packages” in it.
    • Then Copy zconda.pth to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages
  • Testing in ArcGIS Pro
    • Start ArcGIS Pro, open the Python window
    • type “import pysal”
    • type “pysal.” A popup menu with a list of pysal-provided functions is a pretty good sign the install succeeded.
    • conda12
    • conda13
  •  Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arcpro\python.exe
    • conda14
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arcpro environment.

References

  1. USGS: https://goo.gl/xd6xz2
  2. Esri: https://goo.gl/tYGHrw
  3. GeoNet: https://goo.gl/mTLWMG
  4. UC-Davis: http://goo.gl/3bdbwz
REDD+ for the Guiana Shield

Technical Cooperation Project

LidarBlog.com

Dr. Qiusheng Wu @ SUNY Binghamton

Writing Science

How to write papers that get cited and proposals that get funded

GIS In Ecology

Providing Training, Advice And Consultation On The Use Of GIS In Ecology

metrhispanic

On cities, land, ...

GeoAcademy

Open GIS: No Bounds

Scientia Plus Conscientia

Thoughts on Science and Nature

r4hydrology

Learning hydrology with R

Karl Hennermann

GIS at the University of Manchester

GIS and Science

Applications of geospatial technology for scientific research and understanding.

GISblog.com

GIS, Mapping, Remote Sensing, Geodata, Geospatial news

Whitebox Geospatial Analysis Tools

Open-source GIS development and spatial analysis with Whitebox GAT

TopoToolbox

MATLAB-based software for topographic analysis

Anything Geospatial – AnyGeo

Dr. Qiusheng Wu @ SUNY Binghamton

GeospatialPython.com

Dr. Qiusheng Wu @ SUNY Binghamton

Another GIS Blog

Dr. Qiusheng Wu @ SUNY Binghamton

ArcPy Café

Get all your ArcGIS Python Recipes here!

Planet Python

Dr. Qiusheng Wu @ SUNY Binghamton