arcpy.mp.ArcGISProject - OSError

1160
3
12-11-2018 08:52 AM
deleted-user-8TJ6jZDO1Rfr
New Contributor III

I'm having issues using Python in ArcGIS Pro. I'm using Pro 2.2.4 and Spyder (Python 3.6).  I can't get 'arcpy.mp.ArcGISProject' to read my Pro project. I'm running a script to overwrite vector tile packages written by Kelly Gerrow. I added some code to create a vector tile package that worked just fine until this week. Now whenever I try to point to a Pro project it fails with the error below:

I am able to interact with my Pro Project in the python window using 'CURRENT' but not with the arcpy.mp function. 

Here is the error I get when trying to create a vector package using the Python window and the 'CURRENT' project:

Has anyone seen this before? I'm stumped. Dan Patterson Joe Borgione

Tags (2)
0 Kudos
3 Replies
JoeBorgione
MVP Esteemed Contributor

To further elaborate: when I use the arcpy.mp.ArcGISProject() method as shown in James' PythonError.png path to a aprx file on my computer, it works when I run it in a python window. But I get the same error when I run it in a spyder window....

import arcpy

p = arcpy.mp.ArcGISProject(r'C:\Users\JBorgione\Documents\ArcGIS\Packages\LocalGovernment3DBasemaps_F9C2F2D1-1C82-4CB8-B571-1E74A1281032\p20\copy.arpx')

##### error below #####

Traceback (most recent call last):

  File "<ipython-input-25-10564330aca1>", line 1, in <module>
    p = arcpy.mp.ArcGISProject(r'C:\Users\JBorgione\Documents\ArcGIS\Packages\LocalGovernment3DBasemaps_F9C2F2D1-1C82-4CB8-B571-1E74A1281032\p20\copy.arpx')

  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 299, in __init__
    self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))

OSError: C:\Users\JBorgione\Documents\ArcGIS\Packages\LocalGovernment3DBasemaps_F9C2F2D1-1C82-4CB8-B571-1E74A1281032\p20\copy.arpx

Not sure what the OSError is all about.  I can set a variable that paths to the same file just fine in spyder:

file = r'C:\Users\JBorgione\Documents\ArcGIS\Packages\LocalGovernment3DBasemaps_F9C2F2D1-1C82-4CB8-B571-1E74A1281032\p20\copy.arpx'

file
'C:\\Users\\JBorgione\\Documents\\ArcGIS\\Packages\\LocalGovernment3DBasemaps_F9C2F2D1-1C82-4CB8-B571-1E74A1281032\\p20\\copy.arpx'

As James mentioned, this came to us in a script from ESRI, and we are trying to get to work....

Dan Patterson

That should just about do it....
DanPatterson_Retired
MVP Esteemed Contributor

I never use Users folder (we have an expression for that folder).

And as for the rest of the file path... can we squeeze any more punctuation in there!

In a 'normal', simple path.  No problem

Try putting the file in a different location.

pth = r"C:\Git_Dan\arraytools\array_tools_testing\array_tools.aprx"

import arcpy

p = arcpy.mp.ArcGISProject(pth)

dir(p)

Out[275]: ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__',
.... snip.... 'activeMap', 'dateSaved', 'defaultGeodatabase', 'defaultToolbox',
 'documentVersion', 'filePath', 'homeFolder', 'importDocument', 'listBrokenDataSources', 
'listColorRamps', 'listLayouts', 'listMaps', 'listReports', 'save', 'saveACopy',
 'updateConnectionProperties']

Spyder latest version 3.3.2

python 3.6.6 64 bit

ArcGIS PRO Beta 2.3 (although that doesn't make a difference)

JoeBorgione
MVP Esteemed Contributor

Not much of a fan of users directory either, but that install comes free of charge with the ESRI local gov't solutions package. (The dashes '-' are particularly troublesome for me...)  Just for fun:

p = arcpy.mp.ArcGISProject(r'C:\Dans_Folder\copy.aprx')

for m in p.listMaps():
  print(m.name)
  
Schematic Local Government Scene
Map
Map1
Basic Local Government Scene
Realistic Local Government Scene

 This works for me in spyder as well as the python window in Pro.  Need to look at James' install, and maybe reinstall. 

Something isn't right...

That should just about do it....