Select to view content in your preferred language

ArcGIS Pro & Python set up

4795
5
Jump to solution
10-27-2017 02:45 PM
CCWeedcontrol
Frequent Contributor

I am new to ArcGIS Pro, very different from ArcMap. I 've been playing around and trying to get use the new environment. I decided to try a toolbox script that worked in ArcMap (I only installed Pro 2.0.1 i did not add any modules, environments or anything) and I get the following error.

Traceback (most recent call last):
  File "D:\GIS Folder\Python Scripts\ZoomToParcel.py", line 11, in <module>
    mxd = arcpy.mapping.MapDocument("CURRENT")
AttributeError: module 'arcpy' has no attribute 'mapping'
Failed to execute (ZoomToParcel).

I googled ArcGIS Pro & Python, my apologies I am very confused in some threads i read i need to install python 3.5 and in some indicate that i don't need to.Some threads say i need to add new environments and say i don't need to. I come from ArcMap 10.4.1, I use ArcMap python window and python 2.7.10 IDLE shell. I would like to do the same with Pro. Again i am confused and would like simple instructions on how to get ArcPro python and IDLE Shell working  in Pro. I would appreciate any and all the help i can get.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus
  1. mapping is now mp
  2. DO NOT install anything else, especially another version of python.
  3. Go into ArcGIS Pro, go to the Project Page, Click on Python, Install packages and install Spyder if you want a separate python IDE other than contained within ArcGIS Pro
  4. Then make shortcuts to control your Spyder launch from the desktop.  https://community.esri.com/blogs/dan_patterson/2017/07/01/arcgis-pro-2-creating-desktop-shortcuts
  5. Everything is there.  I don't know why ESRI didn't opt to install the Spyder package in the first place so people would have at least one separate python IDE without having to explain how to connect others to it.
  6. If you have another python IDE that you use (except pyscripter, unless the recently released version now works, see if you can do a 'pip' install from within your conda path.

Good luck... ps, check my blog, I have mounds of drivel there associated with python, numpy, scipy, python IDE's, the new 'arcgis' module and Jupyter notebooks.  If you didn't get past 'pip' install, don't worry, just bookmark the blog, it is either there or will be.

PS

I also 'pip' installed pythonwin for the oldschool programming experience (with code folding) and Jupyter (QT console) as other IDE's.  Search this site for those that use others like pycharm etc

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus
  1. mapping is now mp
  2. DO NOT install anything else, especially another version of python.
  3. Go into ArcGIS Pro, go to the Project Page, Click on Python, Install packages and install Spyder if you want a separate python IDE other than contained within ArcGIS Pro
  4. Then make shortcuts to control your Spyder launch from the desktop.  https://community.esri.com/blogs/dan_patterson/2017/07/01/arcgis-pro-2-creating-desktop-shortcuts
  5. Everything is there.  I don't know why ESRI didn't opt to install the Spyder package in the first place so people would have at least one separate python IDE without having to explain how to connect others to it.
  6. If you have another python IDE that you use (except pyscripter, unless the recently released version now works, see if you can do a 'pip' install from within your conda path.

Good luck... ps, check my blog, I have mounds of drivel there associated with python, numpy, scipy, python IDE's, the new 'arcgis' module and Jupyter notebooks.  If you didn't get past 'pip' install, don't worry, just bookmark the blog, it is either there or will be.

PS

I also 'pip' installed pythonwin for the oldschool programming experience (with code folding) and Jupyter (QT console) as other IDE's.  Search this site for those that use others like pycharm etc

curtvprice
MVP Esteemed Contributor

I respectfully disagree with you Dan: definitely not drivel!

0 Kudos
MarcoBoeringa
MVP Regular Contributor

No surprise the toolbox script didn't work straight away. ESRI has had to make some fundamental changes to arcpy for Pro. This means you need to either update the arcpy code to work in Pro only, or write code to deal with the differences so as to make the scripts compatible with both Pro and ArcMap.


The latter is definitely doable. I have converted a complex toolbox with some 50 tools originally developed in ArcMap, to be fully compatible with both Pro and ArcMap. It does mean your code will contain a lot of if..elif statements to deal with the differences, but ultimately, that is not a real big issue, and the number of places you need to insert it in single script is usually limited, as still a lot of the arcpy stuff is compatible between Pro and ArcMap. Usually, only small parts of the script code need to be inside an if..elif or if..else to deal with Pro/ArcMap compatibility, the rest of the code remains unchanged.

Do note that it will certainly take time to familiarize yourself with the differences and how to deal with them. As said, it is doable, but you may run into issues initially trying to understand how to convert code. Nonetheless, ESRI has resources for this, the main stop being this Help page with useful links:

Migrating from arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS Desktop 

As a starter, the following code example shows some minimum stuff all of your scripts will need if you strive for ArcMap/Pro dual compatibility (for some reason, the "Source Code" option of GeoNet does not seem to work? so I insert it directly in the text):


from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import


import arcpy


# GetInstallInfo
installInfoDict = arcpy.GetInstallInfo()
productName = installInfoDict["ProductName"]

if productName in ["Desktop","Server","Engine"]:

        # Your ArcMap code

elif productName in ["ArcGISPro"]:

        # Your Pro code

DanPatterson_Retired
MVP Emeritus

See this blog post for some images etc of Spyder  ... particularly in the Comments section

CCWeedcontrol
Frequent Contributor

Interesting stuff guys, thank you for the great information and links!

0 Kudos