Harnessing the Power of Python in ArcGIS Using the Conda Distribution

Shaun Walbridge

https://github.com/scw/conda-uc-2017

High Quality PDF (2MB)

Python

Why Python?

  • Accessible for new-comers, and the most taught first language in US universites
  • Extensive package collection (56 thousand on PyPI), broad user-base
  • Strong glue language used to bind together many environments, both open source and commercial
  • Open source with liberal license — do what you want

Why Python?

In the box:

Getting to Packages

Why Packages?

  • Software is composed of many smaller components, often called packages or libraries.
  • It’s often better to reuse code that solves a problem well rather than recreating it
  • But, sharing code is a hard problem. Do you have the same packages of the same versions as the developer did?

Package Management for Python

Why not pip, wheels, virtualenvs?

  • Don’t handle the harder problem of system dependencies, considered out of scope by Python packagers — does it end up in site-packages?
  • Package devs: On OSX and Linux, ‘easy’ to get the deps! Use a system package manager (e.g. apt, brew, yum) and the included compiler (e.g. clang, gcc).
  • It’s still not easy to make reproducible builds, and what about Windows?

What about Windows?

  • We are particularly stuck on Windows which lacks broadly used package management
  • Only developers have a C compiler on their machine
  • A hard problem
  • Enter Conda

Why Conda?

  • Scientific Python community identified that there was a gap not being addressed by the core Python infrastructure, limiting their ability to get packages into the hands of users

  • Industry standard built by people who care about this space — Continuum Analytics

Why Conda?

  • It solves a hard problem:

  • Handles dependencies for many languages (C, C++, R and of course Python)
  • Built for Python first, but it really solves a much broader infrastructural issue.
  • E.g. Use it for isolated R installations, which are usually tricky

Conda

  • Cross-platform: simply develop recipes for building and installing software on Linux, OS X and Windows.
  • Open source: Esri is using it, you can use it in your own projects for other contexts

What can it install? Not just scientific packages. It can help with:

  • GUI toolkits (PyQt, TKinter)
  • C++ Libraries (Boost)
  • IDEs (Spyder, Juptyer)

Conda in Pro

  • Environments
    • A collection of packages and Python install is called an environment, the building block for managing Python with Conda
    • Flexibly make changes without affecting installed software
    • Can create multiple environments and switch seamlessly
  • Requirements — include explicit state information, not just the package name.

Conda Basics

Activating environments, a couple ways:

  • Use the shortcuts included in Pro
  • Manually activate the environment:
    cd C:\ArcGIS\bin\Python\Scripts
    activate arcgispro-py3

Conda Basics

conda --help

conda info

Conda info is the starting point — it tells you the state of the environment.

Conda Basics Demo

Conda Basics

Once you’re in an environment get details with info:

conda info

Conda info is the starting point — it tells you the state of the environment.

Conda Basics

conda info

Current conda install:

             platform : win-64
        conda version : 4.0.6
  conda-build version : not installed
       python version : 3.5.1.final.0
     requests version : 2.9.1
     root environment : C:\ArcGIS\bin\Python  (writable)
  default environment : C:\ArcGIS\bin\Python\envs\arcgispro-py3
     envs directories : C:\ArcGIS\bin\Python\envs
        package cache : C:\ArcGIS\bin\Python\pkgs
         channel URLs : https://conda.anaconda.org/esri/win-64/
                        https://conda.anaconda.org/esri/noarch/
                        https://repo.continuum.io/pkgs/free/win-64/
                        https://repo.continuum.io/pkgs/free/noarch/
          config file : C:\ArcGIS\bin\Python\.condarc

Conda Basics

conda list

# packages in environment at C:\ArcGIS\bin\Python\envs\arcgispro-py3:
#
#
colorama                  0.3.7                    py35_0    defaults
cycler                    0.10.0                   py35_0    defaults
future                    0.15.2                   py35_0    defaults
matplotlib                1.5.3              np111py35_0e  [arcgispro]  esri
mpmath                    0.19                     py35_1    defaults
netcdf4                   1.2.4                   py35_0e  [arcgispro]  esri
nose                      1.3.7                    py35_1    defaults
numexpr                   2.6.1              np111py35_0e  [arcgispro]  esri
numpy                     1.11.2                  py35_0e  [arcgispro]  esri
pandas                    0.19.0              np111py35_0    defaults
pip                       8.1.2                    py35_0    defaults
py                        1.4.31                   py35_0    defaults
pyparsing                 2.1.4                    py35_0    defaults
pypdf2                    1.26.0                     py_0    esri
pytest                    2.9.2                    py35_0    defaults
python                    3.5.2                         0    defaults
python-dateutil           2.5.3                    py35_0    defaults
pytz                      2016.6.1                 py35_0    defaults
requests                  2.11.1                   py35_0    defaults
scipy                     0.18.1             np111py35_0e  [arcgispro]  esri
setuptools                27.2.0                   py35_1    defaults
sympy                     1.0                      py35_0    defaults
wheel                     0.29.0                   py35_0    defaults
xlrd                      1.0.0                    py35_0    defaults
xlwt                      1.1.2                    py35_0    defaults

Conda Basics

Creating new environments:

  • A few different ways. Can manually specify the dependencies:
    conda create --name my_env python=3.5 numpy flask dask
  • Can also use a file which includes all the dependencies:

    conda create --name my_env --file my_sweet_depends.txt

    These can contain explcit information about channels, to ensure that the new environment precisely matches the requirements.

Conda vs…

Name Means Will Ship?
Conda The command itself
Miniconda A minimum set of Python packages to build and run Conda.
Anaconda A distribution 200+ packages built with Conda  
Anaconda Server Host the full infrastructure internally  

Deeper Dive

Demo: Conda Package

Multiple Pythons

Currently:

Platform Python version
Desktop Python 2.7 (2.7.13)
Pro Python 3.5 (3.5.3)

Multiple Pythons

Upgrade code? Python migration for ArcGIS Pro

  • Do it! You can support 2 + 3 without that much work
  • Still need to change arcpy.mapping to arcpy.mp when moving from Desktop to Pro, but no Python language level changes needed. . . .


But… this can be costly. For many organizations, a significant burden, even if the language changes are relatively small. Multiple Pythons is a solution to this.

Challenges

Have to make sure you’re running the right Python (what happens when you type python at the command line?)

  • Working to make this easy as possible
  • It’ll be easy to tell in app
  • Isolated installation fixes a variety of issues

  • Requires some user education over the “only one Python on the box” model
  • Upgrades, what happens?

What Do I Get Out of the Box?

  • Conda command and a Conda root Python install
  • New modules (e.g. requests)
  • Conda environment with all of the ArcGIS Pro dependencies as Conda packages

How can I use this?

  • ArcGIS ships with the SciPy stack — powerful and out of the box in all products
  • Conda command and a Conda root Python install
  • New modules (e.g. requests), environment with Pro
  • Python Package Manager in Pro . . .

  • Get packages, expand your possibility space
  • Package your work: this is an opportunity to distribute it

Where Can I Run This?

  • ArcGIS Pro 1.3: first with conda
  • ArcGIS Pro 2.0:
    • Python Package Manager
    • Python 3.5 with current package set
  • ArcGIS Enterprise 10.5
  • ArcGIS API for Python

from future import *

  • Effectively manage complex software dependencies with Conda.
  • Thousands of packages exist today, can integrate it into your organization’s needs.

Closing

Thanks

Esri Conda Team:

Continuum Analytics for creating and open sourcing Conda

Rate This Session

Please take our survey, find session in app and provide review

fin