I recently installed ArcGIS 10.3.1 (previously had 10.1 installed) and I am trying to run a script in Spyder 2.7 that has always worked and getting the below error:

"Traceback (most recent call last):

  File "<ipython-input-4-95832f8a9f6d>", line 1, in <module>
    perimCur = arcpy.SearchCursor(subwatSubPath + subwatPerimsSub[i])

  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\__init__.py", line 1179, in SearchCursor
    return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\geoprocessing\_base.py", line 359, in searchCursor
    self._gp.SearchCursor(*gp_fixargs(args, True)))

RuntimeError: ERROR 999999: Error executing function."

I've tried reinstalling both ArcGIS and Spyder xy, but am still getting the same errors. After looking extensively online, I can't find a solution, although I suspect it may be a path issue. Can anyone help me identify the problem?

I don't know if this is related, but when I import from the spatial analyst module by calling from arcpy.sa import * I get a warning that states unable to detect undefined names.

  • Please include a code snippet so that we know precisely what you have run to see those errors. – PolyGeo Nov 4 '15 at 2:36
  • If you print out your SearchCursor input (subwatSubPath + subwatPerimsSub[i]), what do you get? Also, if you put the line print arcpy.Exists (subwatSubPath + subwatPerimsSub[i]) prior, does it print True (exists) or False? – Emil Brundage Nov 4 '15 at 3:18
  • My code is: import arcpy, os from arcpy import env import arcpy.sa as sa from arcpy.sa import * import numpy as np subwatSubPath = u'C:\\Users\\Cameron\\Desktop\\pythonWorkspace\\subwat/subwat_sub30/' subwatPerimsSub = [i for i in os.listdir(subwatSubPath) if i.endswith('shp')] The subwatPerimSub call returns [u'subPerim1.shp', u'subPerim2.shp']. If I print arcpy.Exists (subwatSubPath + subwatPerimsSub[i]) it returns "True". – help.me Nov 4 '15 at 3:42
  • @help.me, that's not what he meant by "include a code snippet". Please edit your post to include the code and format it as such (highlight the code and hit ctrl+k). – Tom Nov 10 '15 at 0:33

In your comment, you write that subwatSubPath is u'C:\\Users\\Cameron\\Desktop\\pythonWorkspace\\subwat/subwat_sub30/'. That's an odd-looking file path because of the changing slash directions. I would make them consistent (e.g., all \\, or just \ but prefacing the string with r to indicate it's raw and that the escape \ should be ignored, like r"c:\foo\bar"). Consider, also, instead of subwatSubPath + subwatPerimSub[i], doing:

mypath = os.path.join(subwatSubPath, subwatPerimSub[i])

since this takes care of ensuring your paths make sense for the local OS (Windows here).

Also, while arcpy.SearchCursor() should work, it's deprecated, and the new way to get a search cursor is arcpy.da.SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}) - see http://desktop.arcgis.com/en/desktop/latest/analyze/python/data-access-using-cursors.htm

| improve this answer | |
  • Thanks Paulo. My file path is actually r"C:\Users\Cameron\Desktop\pythonWorkspace\subwat" + "NCDE_subwats_all_UTM12N.shp". I wrote it incorrectly in my initial post. It still has changing slash directions, but should be functional. Thanks for your suggestion on how to improve this. I've read about the arcpy.da.SearchCursor, but my understanding is the old versions still are functional. So, it seems like the problem I'm having wouldn't be caused by either file path or cursor type, right? – help.me Nov 4 '15 at 6:19
  • Well, r"C:\Users\Cameron\Desktop\pythonWorkspace\subwat" + "NCDE_subwats_all_UTM12N.shp". is missing a slash before the file name :) Instead, you'd need to do r"C:\Users\Cameron\Desktop\pythonWorkspace\subwat" + r"\" + r"NCDE_subwats_all_UTM12N.shp". The relatively messiness of having to do that is why I always use os.path.join(). Also, it might be that while changing slash directions are okay for Python, the Arc tools don't ingest them well - hence I recommend staying consistent - that way you can be sure it's not that that's bugging your code. – Paulo Raposo Nov 4 '15 at 6:31

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.