I'm new to GIS programming, and am going through the Esri "Getting Started with arcpy.mp" tutorial.

When I try the following:

lyrFile = arcpy.mp.LayerFile(r"path to a layer file") 

I get the following error:

File "", line 1, in File "c:\users\ME\appdata\local\programs\arcgis\pro\Resources\arcpy\arcpy_mp.py", line 773, in init self._arc_object = arcgisscripting._mapping.LayerFile(*gp_fixargs((layer_file_path,), True)) OSError: C:\Users\ME\Documents\ArcGIS\myLayer.lyrx

Typical google search doesn't really bring up much except for Adding feature class to Map in CURRENT project using ArcPy in ArcGIS Pro?

I've tried the alternate methods of adding a Layer file as suggested in the question thread, but get the same OS error.

What is causing this error, so I can figure out how to resolve it?


1 Answer 1


I needed to pay attention to file extensions!

The tutorial assumes you created the layer file in ArcGIS Pro. I was attempting to add a layer created in ArcGIS Desktop 10.5, which has the '.lyr' extension, NOT '.lyrx'.

  • For those whom this answer did not suffice, be sure to check something as simple as whether you spelled the name of the layer file correctly, or whether the file path is correct! OSError comes up with something related to the system, not arcpy.
    – jesnes
    Dec 9, 2019 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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