Why does arcpy.mp.ArcGISProject() give an OSError?

8596
9
Jump to solution
06-01-2017 08:07 PM
MatthewCallahan1
New Contributor II

I read the "Guidelines for arcpy.mp" doc, but when I call the sample code myself in the ArcGIS Pro Python window or from a Python script, I get this error:

import arcpy
aprx = arcpy.mp.ArcGISProject(r'C:\Path\To\Project\test_project.tbx')

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 283, in __init__
    self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))
OSError: C:\Path\To\Project\test_project.tbx

Is this normal expected behavior?  The example code shows setting the project variable with an explicit .aprx file path, and I'm wondering why I'm unable to do the same on my machine.  The .aprx file is present/there are no misspellings in the file path in my code.  For reference, I'm running a fresh Windows 7 64-bit install with a fresh ArcGIS Desktop install as well (Pro v 1.4.1).

1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

from the help topic why don't you reference the *.aprx, then you can get the toolbox as one of its properties.  You are referencing the toolbox (tbx) directly.

View solution in original post

9 Replies
DanPatterson_Retired
MVP Emeritus

from the help topic why don't you reference the *.aprx, then you can get the toolbox as one of its properties.  You are referencing the toolbox (tbx) directly.

MatthewCallahan1
New Contributor II

lol I'm dumb, that was it!  Time for bed, enough Python for today!

0 Kudos
chill_gis_dude
New Contributor III

Hi Dan, I have this same problem but with the aprx file. I actually have a couple scripts I use to toggle label classes and layers off before exporting a map series. I was hoping to get the script to run outside of pro as a scheduled task but whenever I replace r"Current" with the project file path it just doesn't do anything even from within the project. 

#Toggle Layers Off
import arcpy
aprx = arcpy.mp.ArcGISProject(r"\\prowl\share\GIS\Data\Projects\Ranch Maps\RanchMaps\RanchMaps.aprx")
m = aprx.listMaps("Default Map*")[0]
lyrList = m.listLayers()
for lyr in lyrList:
  if lyr.isGroupLayer:
    lyr.visible = True
  if lyr.longName == "Block Names":
    lyr.visible = True
  if lyr.longName == "Block Details":
    lyr.visible = False
0 Kudos
KevinChristy1
Occasional Contributor

Dan, might you know why one would get this same exact error, but I am actually referencing the *aprx file?

MichaelVolz
Esteemed Contributor

Would you need to use Current in this circumstance?

0 Kudos
KevinChristy1
Occasional Contributor

Disregard, I realized that due to the nature that my project file and .aprx had the same name that I was omitting the project folder...Thanks though!

ShraddhaSharma
New Contributor II

Hi Dan I am also facing the same problem but with my aprx file. 

0 Kudos
AllenDailey1
Occasional Contributor III

I'm having the same error, but with my .aprx path, not with a toolbox path.  Have any of you been able to solve the problem?

Thanks!

0 Kudos
AllenDailey1
Occasional Contributor III

I think I figured it out.  I haven't 100% tested this yet, but I believe the error resulted from the .aprx being Pro 3.0 while the machine I was running my script on had Pro 2.7, so it could not open or use the .aprx.  I am going to upgrade that machine to Pro 3.0 sometime this week.

Update:  it worked!