Trouble creating `Layer` objects in ArcGIS Pro 2.2.4

1134
6
Jump to solution
11-07-2018 01:50 PM
AustinOrr
New Contributor II

Hi All, I'm having much difficulty with the Make Feature Layer examples from the docs here

I'm running arcpy from a standalone script using the "c:\Program Files\ArcGIS\Pro\bin\Python\scripts\proenv.bat" provided by ESRI. 

In their example, it is possible to set the workspace, and then pass a shapefile inside that workspace to the `MakeFeatureLayer_management` function. When I try this in a minimal script I get an unhelpful error message.

<test.py>

import arcpy
print(arcpy.GetInstallInfo())
ws = 'C:\\Users\\myself\\testing\\test_query_bboxes'
fc = 'test_bboxes.shp'

arcpy.env.workspace = ws
arcpy.MakeFeatureLayer_management(fc, 'test_lyr')

<output>
{'InstallDir': 'c:\\program files\\arcgis\\pro\\',  
'Installer': 'myself',  
'ProductName': 'ArcGISPro',  
'Version': '2.2.4',  
'SourceDir': 'C:\\Users\\myself\\Documents\\ArcGIS Pro 2.2\\ArcGISPro\\',  
'InstallType': 'N/A',  
'BuildNumber': '12813',  
'InstallDate': '11/7/2018',  
'InstallTime': '12:51:07',  
'SPNumber': 'N/A',  
'SPBuild': 'N/A'}

RuntimeError Traceback (most recent call last)
<ipython-input-1-f8756495bde9> in <module>()
 5 
 6 arcpy.env.workspace = gdb
----> 7 arcpy.MakeFeatureLayer_management(fc, 'test_lyr')

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in MakeFeatureLayer(in_features, out_layer, where_clause, workspace, field_info)
 6532 return retval
 6533 except Exception as e:
-> 6534 raise e
 6535 
 6536 @gptooldoc('MakeImageServerLayer_management', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in MakeFeatureLayer(in_features, out_layer, where_clause, workspace, field_info)
 6529 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
 6530 try:
-> 6531 retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True)))
 6532 return retval
 6533 except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
 494 val = getattr(self._gp, attr)
 495 if callable(val):
--> 496 return lambda *args: val(*gp_fixargs(args, True))
 497 else:
 498 return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool

```

This works great with the `arcpy` from ArcMap 10.6 for both compete paths to the input featureclass (both in geodatabases an as shapefiles) and as names within the workspace. What am in missing about how i'm supposed to initialize a `Layer` object in `arcpy` from ArcGIS Pro?

0 Kudos
1 Solution

Accepted Solutions
AustinOrr
New Contributor II

I'm closing this question. 

I've contacted ESRI regarding this issue and it relates to their application architecture decision to ship miniconda within their application. If you are a python developer who already uses miniconda, you will have to delete all of your environments, uninstall miniconda/Anaconda and forever manage your conda environments with ArcGIS "Pro" (which is clearly not for professionals who already program in python).

If any conda users know of a workaround for this case, please reply in this thread.

View solution in original post

6 Replies
JoshuaBixby
MVP Esteemed Contributor

I just tried your code using ArcGIS Pro 2.2.2 on my machine and it worked fine.  I will test again after I apply the 2.2.4 patch.

0 Kudos
AustinOrr
New Contributor II

Thanks for checking, I don't think I can roll back to 2.2.2 to see if it's a bug in 2.2.4. It seems unlikely that this is a regression, but their release notes do indicate that there may have been work done in the layer management code base between these two releases.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Yep, works in 2.2.4 too.

DanPatterson_Retired
MVP Emeritus
pth = r"C:\GIS\Centre_Ottawa\Data"

import arcpy
print(arcpy.GetInstallInfo())
ws = pth
fc = 'WardPopCT.shp'

arcpy.env.workspace = ws
arcpy.MakeFeatureLayer_management(fc, 'test_lyr')


{'InstallDir': 'c:\\arcgispro\\',
 'Installer': 'dan_p',
 'ProductName': 'ArcGISPro',
 'Version': '2.2.4',
 'SourceDir': 'C:\\Computer\\ArcGISPro_2_2\\ArcGISPro\\',
 'InstallType': 'N/A',
 'BuildNumber': '12813',
 'InstallDate': '2018-11-06',
 'InstallTime': '18:41:08',
 'SPNumber': 'N/A',
 'SPBuild': 'N/A'}

Out[2]: <Result 'test_lyr'>

worked for me...

AustinOrr
New Contributor II

I'm closing this question. 

I've contacted ESRI regarding this issue and it relates to their application architecture decision to ship miniconda within their application. If you are a python developer who already uses miniconda, you will have to delete all of your environments, uninstall miniconda/Anaconda and forever manage your conda environments with ArcGIS "Pro" (which is clearly not for professionals who already program in python).

If any conda users know of a workaround for this case, please reply in this thread.

JoshuaBixby
MVP Esteemed Contributor

Although I can understand having to use ArcGIS Pro's conda environment to use ArcPy, that doesn't mean one has to delete all of your environments and other conda installations.  I run Pro's conda environment as well as a second miniconda environment, and I don't have any issues.  Maybe I am just misreading what you summarized.

0 Kudos