Select to view content in your preferred language

Python 2 AND Python 3 ArcGIS requirements

01-17-2019 04:58 AM
Regular Contributor

I've in the processing of transitioning some Python 2 arcpy geoprocessing workflows to Python 3 so I can also incorporate the ArcGIS Python API into the workflows.

As such, I need both versions installed on a single computer, and both able to leverage the arcpy library.  

Does that mean I need to install ArcMap AND ArcGIS Pro on my machine?  Is there any way to get this accomplished with JUST ArcGIS Pro?   

6 Replies
Esri Esteemed Contributor

There is no problem with installing ArcMap and ArcGIS Pro on the same machine. Both come with their respective version of Python. The geoprocessing workflows you want  to migrate to 3.x are desktop script tools or geoprocessing services?

There are tools that allow you to validate the script and validate compatibility: Analyze Tools For Pro—Data Management toolbox | ArcGIS Desktop 

But in short, yes you could do this with only ArcGIS Pro installed. 

Regular Contributor

They're mostly standalone script tools for data pipelines - web scraping and arcpy.da.Update and Insert cursors for our enterprise database, as well as some standard geoprocessing workflows (intersects, buffers, etc. etc.).  So they rely heavily on the arcpy library.  

I don't know how to access the Python's 2.x arcpy library without having ArcMap installed, and migrating scripts to Python's 3.x arcpy library will allow me to ALSO take advantage of the ArcGIS API for Python (e.g. use arcpy to update an enterprise database with some geodata, and then use the ArcGIS Python API to update an Enterprise Portal for ArcGIS item to list when the underlying geodata was last updated or print a web map of the new data, all in the same script).  

0 Kudos
MVP Esteemed Contributor

You cannot use ArcPy without having an ArcGIS product installed and licensed on a machine, so the question becomes which product.  There are server options for using ArcPy with Python 2.x, but that is even more expensive and complex than ArcMap.  If you want to use ArcPy with Python 2.x and 3.x, your only option is to install both ArcMap and Pro.

MVP Emeritus

Server stuff aside, since I don't use one... I used python 3 to develop scripts that worked in 2.7 and arcmaps arcpy long before ArcGIS pro was around.

You will notice many code bases that support python 2.x and 3.x rely on imports from the __future__ module 

28.11. __future__ — Future statement definitions — Python 2.7.15 documentation 

So it is not uncommon to see

from __future__ import (absolute_import, division,
                        print_function, unicode_literals)
from builtins import *

when people are writing code that needs to support the 2.7 and 3.x code base.

In general skip writing for 2.7, write for 3.x since 2.7 support is being dropped or has been dropped already by many of the python packages that people might use for gis applications (ie numpy, scipy, pandas etc etc)

You can also skip things altogether (I have had success with this) by writing for toolsets for use in arctoolbox in ArcGIS Pro 2.3, for example, then exporting them for use in versions of ArcMap....

/blogs/dan_patterson/2016/05/09/the-links provides links to some resources which might help make the transition...

But in any event

Python 2.7 Countdown is inevitable...

Regular Contributor

Sure, I can certainly write scripts with in 2.x that will work for 3.x using the __future__ module, but in order to utilize arcpy in the 3.x python (which I also need for ArcGIS Python API), I still need ArcGIS Pro installed.  

0 Kudos
MVP Emeritus

of course you need Pro installed, arcpy is different between the *map and *pro incarnations.  The point I was making is to skip writing python 2.7 so it will work in 3.x, the otherway around is what I have done.  The "from __future___..." are ignored by python 3.x and are only needed for convenience for the 2.7 versions that are used with ArcMap.

Rumours of ArcMap 10.7 appearing suggest that esri will continue to support the python 2.7 code base  even though there will be no updates to it beyond 2020.  At some point, maintaining 2 arcpys and 2 whatevers will wear thin and ArcMap will become 'legacy' as many of its predecessors have experienced (aka ArcMap 3.x, Avenue... even Cobol )

ArcGIS Pro is pretty good at not getting muddled by a python 2.7/ArcMap installation.  Which is part of the reason they use an Anaconda distribution of python and you should 'Clone' your 3.x environment since a pristine installation of *pro needs to be maintained.