Basic Question for arcpy.mp.ArcGISProject()

796
2
07-06-2021 09:07 PM
kelvpau
New Contributor

Hi, I just have a basic question with the arcpy.mp.ArcGISProject()  function while trying to follow along a simple tutorial that is a bit old. Here's the relevant code section below

# Import modules
import arcpy

# Create the map document object
aprx = arcpy.mp.ArcGISProject(r"C:\Users\User\Documents\ArcGIS\Projects\MyProject2.aprx")

And this is the OS Error in question:

Traceback (most recent call last):
File "C:\Users\User\Desktop\Exercise ArcGis Python\Ex_Files_ArcGIS_Python_Scripting\Exercise Files\WorkWithListsFinal.py", line 15, in <module>
aprx = arcpy.mp.ArcGISProject(r"C:\Users\User\Documents\ArcGIS\Projects\MyProject2.aprx")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 344, in __init__
self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))
OSError: C:\Users\User\Documents\ArcGIS\Projects\MyProject2.aprx

Not really sure what's happening here to not allow me reference the .aprx file which is what I thought the ArcGISProject() command did.

Tags (2)
0 Kudos
2 Replies
JayantaPoddar
MVP Esteemed Contributor

From Windows Explorer, could you ensure that the filepath of the aprx file is correct?

Just my assumption, maybe you missed the folder containing the aprx file (e.g. "C:\Users\User\Documents\ArcGIS\Projects\MyProject2\MyProject2.aprx")

or any other pathname



Think Location
DanPatterson
MVP Esteemed Contributor

unless you altered the path

 C:\Users\User\Documents\ArcGIS\Projects\MyProject2.aprx

probably should be

 C:\Users\.. your user name ...\Documents\ArcGIS\Projects\MyProject2.aprx

where  "your user name" is your identifier


... sort of retired...
0 Kudos