1

I'm having difficulty with the Make Feature Layer examples.

I'm importing arcpy from a standalone script using the "c:\Program Files\ArcGIS\Pro\bin\Python\scripts\proenv.bat" provided by ESRI. This activates the environment, then I use:

(arcgispro-py3) > python test.py

to run it. There are no issues importing arcpy and I get the same error if I try the script with ArcGIS Pro running, and with 'use offline' enabled. I do not think this is a license authentication issue or arcpy would not import.

In their docs 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.

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')

{'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

To be clear, this function works as expected 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 I missing about how to initialize a Layer object in arcpy from ArcGIS Pro 2.2.4?

UPDATE:

I've contacted ESRI regarding this issue and learned that 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). This is obviously ridiculous for programmers since uninstalling ArcPro would delete all of their python environments. For now I will need to abandon efforts to program on this platform and continue using ArcMap until ESRI ships a version of Pro that allows users to manage their own python environments.

I'm leaving this question unanswered so that any conda users who also use ESRI products that know of a workaround can get credit for an answer.

Here's what I've tried that doesn't work:

  • removing conda from your system & user PATH variable, restarting, deleting the 'Python' folder from the ArcGIS Pro installation, repairing the ArcGIS Pro application to re-build the 'Python' directory, and trying again. Same error as above. I'm amazed that this doesn't work, since my pre-existing conda install lives in my users folder and shouldn't conflict with paths and prefixes anymore.

  • cloning the arcgispro environment with >conda create --clone "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3". Same error as above. This was a long shot, but still a no go.

  • calling the script with the full path to the python.exe "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" test.py. Same error as above. This method works awesome for running things with the ArcMap python installation pattern. I'm very sad this pattern does not work with ArcGIS Pro, honestly there is no real excuse for this not to work (I even tried it with the application running so that I could be sure that authentication was not the issue). Disappointing.

I'm out of ideas at this point and ready to wait on switching to ArcGIS Pro until it plays nicely with existing users of conda. If you've got an insight, please answer or comment!

  • You need the full path to fc or set your workspace to the folder the shape file is in... the unhelpful error no doubt says I can't find that file more or less. Can you confirm the shapefile exists in the nominated workspace and isn't corrupt? – Michael Stimson Nov 7 '18 at 22:58
  • @Michael Stimson, I think i'm doing what you're saying in lines 3 and 4 of my test script. I also indicate that this works fully as expected in ArcMap 10.6's arcpy which should mean that the shapefile exists and is not corrupt. – aorr Nov 8 '18 at 2:44
  • Can you try it with a different shapefile or geodatabase feature class in a different location.. the C:\Users\.. folder can have special permissions. Also, can you look at your environ TEMP and TMP print(os.environ.get('TEMP')) then print(os.environ.get('TMP')) then print(arcpy.scratchWorkspace), check all these folders exist, to ensure your temp and scratch workspace are fine. – Michael Stimson Nov 8 '18 at 3:03
  • @Michael Stimson, as stated in the question, I have tried it with both feature classes in geodatabases and with shapefiles. I do not think that c:\users\myself has any tricky permissions since I am myself (that’s where my desktop and documents folders are... you might be thinking of c:\Progam Files or the naked c:\ directory which both have tricky permissions). I’ll try your environ TEMP leads tomorrow though. I also tried to create this file explicitly in memory using the path ‘in_memory\test_lyr’ to no avail. – aorr Nov 8 '18 at 6:21
1

As a test I would try this instead:

import arcpy
fc = 'C:\\Users\\myself\\testing\\test_query_bboxes\\test_bboxes.shp'
arcpy.MakeFeatureLayer_management(fc, 'test_lyr')
  • 1
    I get the same error when I pass the full path as when i pass a filename in the workspace. Also note that this same script works as expected on the same machine under ArcMaps 10.6 arcpy variant. – aorr Nov 8 '18 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.