Python Won't Run Spatial Autocorrelation Script Twice

Discussion created by ajs5325 on Oct 9, 2012
Latest reply on Jul 7, 2014 by juan_marco

I'm trying to calculate a Global Moran's I statistic on a [long] list of point files using python.  I have set up my code to loop through the arcpy.SpatialAutocorrelation_stats script as shown below.  The loop runs through the first shapefile without a problem and prints out the Moran's I Summary Table.  When it gets to the second shapefile, it crashes with a strange error. 

I can manually run the Spatial Autocorrelation Script in batch form without a problem from ArcCatalog.  However, I don't want to parse through the Results window later. 

I am using ArcGIS 10.1 with Python XY (Spyder) 2.7 on a Windows 7 64-bit machine.

Has anyone encountered this error or found any solutions?


import arcpy
dataPath = r"c:\data"
elevationPoints = ["elevPts1.shp", "elevPts2.shp"]
elevationPoints = ["id_1pt.shp","id_11pt.shp"]
dataPath = r"C:\Users\Andy\Desktop\BlackbirdKnob_WV\tempPts"
for i in range(len(elevationPoints)):
    arcpy.SpatialAutocorrelation_stats (dataPath+"\\"+elevationPoints[i], "GRID_CODE", "NO_REPORT" , "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE" ,"NONE","15")

This is the error message that comes up:
Traceback (most recent call last):
  File "C:\Users\Andy\Desktop\MoransLoop.py", line 20, in <module>
    arcpy.SpatialAutocorrelation_stats (dataPath+"\\"+elevationPoints[i], "GRID_CODE", "NO_REPORT" , "FIXED_DISTANCE_BAND", "EUCLIDEAN_DISTANCE" ,"NONE","15")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\stats.py", line 403, in SpatialAutocorrelation
    raise e
Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\MoransI.py", line 21, in <module>
    import SSReport as REPORT
  File "c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Scripts\SSReport.py", line 17, in <module>
    import pylab as PYLAB
  File "C:\Python27\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Python27\lib\site-packages\matplotlib\pylab.py", line 264, in <module>
    from matplotlib.pyplot import *
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module>
    from matplotlib.figure import Figure, figaspect
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 338, in <module>
    class Axes(martist.Artist):
  File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 2051, in Axes
    def grid(self, b=None, which='major', axis='both', **kwargs):
  File "C:\Python27\lib\site-packages\matplotlib\docstring.py", line 103, in dedent_interpd
    return interpd(dedent(func))
  File "C:\Python27\lib\site-packages\matplotlib\docstring.py", line 36, in __call__
    func.__doc__ = func.__doc__ and func.__doc__ % self.params
KeyError: 'Line2D'

Failed to execute (SpatialAutocorrelation).