I am attempting to complete an exercise in chapter 11 of the book "Python Scripting for ArcGIS Pro". One of the example code bits i'm trying to run is this:
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\shildebr\Documents\PythonScripting_Ex11_Data\Ex11\Austin.aprx")
print(aprx.defaultGeodatabase)
When I run this I get this message:
File "H:/EsriTraining/Python Scripting for ArcGIS Pro/PythonScripting_Ex11_Data/Ex11/projects.py", line 2, in <module>
aprx = arcpy.mp.ArcGISProject(r"C:\Users\shildebr\Documents\PythonScripting_Ex11_Data\Ex11\Austin.aprx")
AttributeError: 'module' object has no attribute 'mp'
Isn't "defaultGeodatabase" a property of the ArcGISProject object? I'm really confused as to why this won't run.
Are you sure you are using the version of python that comes with ArcGIS Pro?
mp is for Pro, mapping is for ArcMap
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\blank.aprx")
and the default geodatabase is a read/write property
ArcGISProject—ArcGIS Pro | Documentation
The error is
not
arcpy is your module object and python is telling you it has no "mp" attribute. Which sounds to me (like Dan says) that you're probably running your script using ArcGIS Desktop Python 2.7 not ArcGIS Pro Python 3.
Ok thanks, I thought it had to be something like that. I'm running these in 2.7. Somehow 3 never got installed when Pro was installed.
I suspect that your python IDE isn't pointing to the correct version of python.
Python 3 is part of the arcgis pro installation. You can confirm using file explorer and looking for
C:\...Your_Pro_Installation_Folder...\bin\Python
where you installed Pro
Ok, when I open IDLE (Python GUI), the version is 2.7. We do have Pro installed and can confirm that python 3 is installed in the folder you mentioned. How do you open IDLE to use python 3?
I get an "Edit with IDLE (ArcGIS Pro)" context menu entry when I right click a python file. You can also open an ArcGIS Pro Python command prompt: Start - ArcGIS - Python Command Prompt and type "idle"
you can also open Pro and start a Notebook or edit it in Pro's python window
Notebooks in ArcGIS Pro—ArcGIS Pro | Documentation
Python window—ArcGIS Pro | Documentation