Select to view content in your preferred language

ArcPy Mapping Module has no attribute

10722
7
04-27-2021 03:01 PM
shildebrand
Frequent Contributor

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.

Tags (2)
0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
Luke_Pinner
MVP Regular Contributor

The error is

  • "AttributeError: 'module' object has no attribute 'mp'"

not

  • "AttributeError: 'ArcGISProject' object has no attribute 'defaultGeodatabase'"

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.

 

0 Kudos
shildebrand
Frequent Contributor

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.

0 Kudos
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
shildebrand
Frequent Contributor

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?

0 Kudos
Luke_Pinner
MVP Regular Contributor

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"

https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/installing-python-for-arcgis-pro.htm#:~:t....

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos