Top Banner
Harnessing the Power of Python in ArcGIS Using the Conda Distribution Shaun Walbridge Mark Janikas Ting Lee
46

Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Jun 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

HarnessingthePowerofPythoninArcGISUsingtheCondaDistributionShaunWalbridge

MarkJanikas

TingLee

Page 3: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Conda

Page 4: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBrandnew:thoughtitwasmoreimportanttoshowittoyouthantofocusontellingyouaboutitTimetodaytodiscussyourneedsandwhatwemightdotosolveyourproblems

Page 5: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhyPython?Accessiblefornew-comers,andthe

Extensivepackagecollection(56thousandon ),broaduser-baseStronggluelanguageusedtobindtogethermanyenvironments,bothopensourceandcommercialOpensourcewithliberallicense—dowhatyouwant

mosttaughtfirstlanguageinUSuniversites

PyPI

Page 6: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

PackageManagementforPython

Whynotpip,wheels,virtualenvs?Don’thandletheharderproblemofsystemdependencies,consideredoutofscopebyPythonpackagers—doesitendupinsite-packages?Packagedevs:OnOSXandLinux,‘easy’togetthedeps!Useasystempackagemanager(e.g.apt,brew,yum)andtheincludedcompiler(e.g.clang,gcc).It’sstillnoteasytomakereproduciblebuilds,andwhataboutWindows?

Page 7: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhataboutWindows?WeareparticularlystuckonWindowswhichlacksbroadlyusedpackagemanagement

NuGetisgreat,butnotasystem-levelpackagemanagerIfmanagingapplications,try

OnlydevshaveaCcompilerontheirmachineTheessentialmodeliscompilersforfew,runtimesforall

Packagemanagementishard!(ExceptonJavaScript–universalcompilersarealeg-up)

Chocolatey

Page 8: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhataboutWindows?WeareparticularlystuckonWindowswhichlacksbroadlyusedpackagemanagement

NuGetisgreat,butnotasystem-levelpackagemanagerIfmanagingapplications,try

OnlydevshaveaCcompilerontheirmachineTheessentialmodeliscompilersforfew,runtimesforall

Packagemanagementishard!(ExceptonJavaScript–universalcompilersarealeg-up)

EnterConda

Chocolatey

Page 9: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhyConda?

ScientificPythoncommunityidentifiedthattherewasagapnotbeingaddressedbythecorePythoninfrastructure,limitingtheirabilitytogetpackagesintothehandsofusers

Industrystandardbuiltbypeoplewhocareaboutthisspace–ContinuumAnalytics

Page 10: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhyConda?

Itsolvesahardproblem:

Handlesdependenciesformanylanguages(C,C++,RandofcoursePython)

BuiltforPythonfirst,butitreallysolvesamuchbroaderinfrastructuralissue.

Page 11: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Conda

Page 12: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaCross-platform:simplydeveloprecipesforbuildingandinstallingsoftwareonLinux,OSXandWindows.Allittakes:ameta.yaml,andabuildrecipe.Opensource(BSD):Esriisusingit,youcanuseitinyourownprojectsforothercontexts

Page 13: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaWhatcanitinstall?Notjustscientificpackages.Itcanhelpwith:

GUItoolkits(PyQt,TKinter)C++Libraries(Boost)IDEs(Spyder,Juptyer)

See foracomprehensivesetofbuildrecipes.EverythingfromapplicationstocompilerstoPythonmodules,hundredsofmaintainedrecipesacrossmanyproblemdomains.

conda-recipes

Page 14: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaEnvironments:CanisolateaPythonenvironment,flexiblymakechangeswithotaffectinginstalledsoftware.Requirements–includeexplicitstateinformation,notjustthepackagename.Namesaren’tenough!AlsohandlesplatformsandJupyternotebooks

Page 15: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

HowDoesitWork?Condapackagescancomefromavarietyoflocations:

Ondisk(file://)PublicrepositorieshostedonAnacondaCloudPublicrepositoriesself-hostedPrivaterepositoriesPaidprivaterepositories

Page 16: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsCommandlineinterface

Willshowwhatwe’reworkingontomakethiseasier,especiallyfornon-developers

CondaCheatsheet

Page 17: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsTostart:

AcollectionofpackagesandPythoninstalliscalledanenvironmentorenv,thebuildingblockformanagingPythonwithCondaCanhavemultipleenvironmentsandseamlesslyswitchbetweenthem

conda --help

Page 18: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsActivatingenvironments,acoupleways:

UsetheshortcutsManuallyactivatetheenvironment:

cd /d C:\ArcGIS\bin\Python\Scripts activate arcgispro-py3

Page 19: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsOnceyou’reinanenvironmentgetdetailswithinfo:

Condainfoisthestartingpoint–ittellsyouthestateoftheenvironment.

conda info

Page 20: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsconda info

Current conda install:

platform : win-64 conda version : 4.0.4 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

Page 21: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsconda list

# packages in environment at C:\ArcGIS\bin\Python\envs\arcgispro-py3:#arcgispro 1.0 0 esrimatplotlib 1.4.3 np19py34_0 defaultsnose 1.3.7 py34_0 defaultsnumpy 1.9.3 py34_0e [arcgispro] esripandas 0.17.1 np19py34_0 esripip 8.0.3 py34_0 defaultspyparsing 2.0.3 py34_0 defaultspypdf2 1.25.1 py_0 esripython 3.4.4 2 defaultspython-dateutil 2.4.2 py34_0 defaultspytz 2015.7 py34_0 defaultsscipy 0.16.1 np19py34_0e [arcgispro] esrisetuptools 20.1.1 py34_0 defaultssix 1.10.0 py34_0 defaultssympy 0.7.6.1 py34_0 defaultswheel 0.29.0 py34_0 defaultsxlrd 0.9.4 py34_0 defaultsxlwt 1.0.0 py34_0 defaults

Page 22: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBasicsCreatingnewenvironments:

Afewdifferentways.Canmanuallyspecifythedependencies:

Canalsouseafilewhichincludesallthedependencies:

Thesecancontainexplcitinformationaboutchannels,toensurethatthenewenvironmentpreciselymatchestherequirements.

conda create --name my_env python=3.4 numpy flask dask

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

Page 23: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Condavs…Name Means Will

Ship?

Conda Thecommanditself ✓Miniconda AminimumsetofPythonpackagesto

buildandrunConda.✓

Anaconda Adistribution200+packagesbuiltwithConda

AnacondaServer

Hostthefullinfrastructureinternally

Page 24: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaDemo

Page 25: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

DeeperDive

Page 26: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CondaBehindFirewallHow’sitwork?

Lockitdown:Don’tusenetwork

Canvettheinstallation

Willworkoutoftheboxwithdefaultpackageswithoutanynetworkconnectivity

Page 27: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

.condarcModifydefaultswithasimplesimpleYAMLfileforconfigurationCanbeupdatedwithconda config,justlikeusinggit configtoupdatethedefaultconfiguration

Adetailedexample.condarc

Page 28: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

CreatingpackagesStraightforward:

Ametadatadocument(meta.yaml)specifyingthecontentsanddependenciesAbuildcommand(bld.bat,build.sh)specifyinghowtobuild

Page 29: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Creatingpackagesmeta.yaml:

package: name: pypdf2 version: "1.25.1"

source: fn: PyPDF2-1.25.1.tar.gz url: https://pypi.python.org/packages/source/P/PyPDF2/PyPDF2-1.25.1.tar.gz md5: ee5e5b01d00b120805e5049e56c6fd7c

requirements: run: - python

Page 30: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Creatingpackagesbld.bat:

"%PYTHON%" setup.py install

Page 31: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

MultiplePythonsCurrently:

Platform Pythonversion

Desktop Python2.7.x(2.7.10)

Pro Python3.4.x(3.4.3)

Page 32: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

MultiplePythonsUpgradecode?

Doitalready!Youcansupport2+3withoutthatmuchworkIfyouhitanissue,it’sprobablybecauseyoudon’tunderstandUnicodeyet– ,PragmaticUnicode,or,HowdoIstopthepain?

PythonmigrationforArcGISPro

WatchthisPyContalk

Page 33: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

MultiplePythonsUpgradecode?

Doitalready!Youcansupport2+3withoutthatmuchworkIfyouhitanissue,it’sprobablybecauseyoudon’tunderstandUnicodeyet– ,PragmaticUnicode,or,HowdoIstopthepain?

But…thiscanbecostly.Formanyorganizations,asignificantburden,evenifthelanguagechangesarerelativelysmall.

PythonmigrationforArcGISPro

WatchthisPyContalk

Page 34: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

MultiplePythonswithConda

WithConda,wecansupportmultipleplatforms:

Py2.7,3.4,3.5inPro1.3

Createanewenvironment,targetadifferentPython,userscannowusethatwiththePy2code

Stillneedtochangearcpy.mappingtoarcpy.mpwhenmovingfromDesktoptoPro,butnoPythonlanguagelevelchangesneeded.

Page 35: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

ChallengesHavetomakesureyou’rerunningtherightPython(whathappens

whenyoutypepythonatthecommandline?)WewillmakethiseasyaspossibleIt’llbeeasytotellinappIsolatedinstallationfixesavarietyofissues

Requiressomeusereducationoverthe“onlyonePythononthebox”model

Page 36: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhatDoIGetOutoftheBox?

CondacommandandaCondarootPythoninstallNewmodules(e.g.requests)CondaenvironmentwithalloftheArcGISProdependenciesasCondapackages

Page 37: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

HowcanIusethis?WealreadyshipyoutheSciPystack–powerfulandoutofthebox,canusetoday(Proand10.4)Canstartusingcondatoday.Minicondaisfullystand-alone,won’taffectyourglobalPython(unlessyoutellitto)Packageyourwork:thisisanopportunitytodistributeit,possiblyincludingcommercialsideaswell.

Page 38: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

WhereCanIRunThis?

ArcGISPro1.3(Release:2016UC)WillbethePythoninstall.UIforinteraction

Future:TakeadvantageofmorefeaturesIntegrationwithplatform

Page 39: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

fromfutureimport*EffectivelymanagecomplexsoftwaredependencieswithConda.Thousandsofpackagesexisttoday,canintegrateitintoyour

organization’sneeds.

Page 40: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Resources

Page 42: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

Closing

Page 43: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

ThanksEsriCondaTeam:

ContinuumAnalyticsforcreatingandopensourcingConda

Page 44: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

RateThisSessioniOS,Android:Feedbackfromwithintheapp

WindowsPhone,don’tuseasmartphone?:Cuniformtabletsaccepted(sorry!limitation).

Page 45: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS

RateThisSessioniOS,Android:Feedbackfromwithintheapp

WindowsPhone,don’tuseasmartphone?:Cuniformtabletsaccepted(sorry!limitation).

WindowsPhone,ornosmartphone?Cuneiformtabletsaccepted.

Page 46: Harnessing the Power of Python in ArcGIS using the Conda ...€¦ · 2016 Esri Developer Summit--Presentation, 2016 Esri Developer Summit, Harnessing the Power of Python in ArcGIS