2

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?

6
  • Are you using ArcGIS Desktop or ArcGIS Pro? lyrx is a ArcGIS Pro layer file Commented Oct 24, 2018 at 13:29
  • 1
    Yep, just discovered my error! Doing tutorial in Pro, trying to use layer created in Desktop 10.5 which has a '.lyr' extension, not '.lyrx' Commented Oct 24, 2018 at 13:38
  • I save as the .lyrx layer in ArcPro but still get the same error. Commented Nov 5, 2018 at 13:37
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review Commented Nov 5, 2018 at 14:04
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Nov 5, 2018 at 14:19

1 Answer 1

2

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

1
  • 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. Commented Dec 9, 2019 at 17:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.