Why does my code work in ArcMap but not in IDLE?
It is similar to: ArcPy function works in ArcMap Python window but not from standalone script? except that the answer to that question does not apply to me.
I also am not just running a function from my script in the python window. I am running the exact same script.
There is also Script runs in ArcMap Python window but not in standalone PythonWin or IDLE? but no great answer there.
I suspect it has something to do with Geoprocessing Options (my specific hunch is "background processing"?) that may not apply when I'm using IDLE (see last screenshot) but I'd really like to know what specifically causes this so I can run scripts like this from IDLE (and not from ArcMap every time). Is there a way to set options like this in the script? I am using 10.3.1 so I assumed what I've read about needing to install background processing no longer applies.
I wrote this script to process contours from a series of smoothed DEMs. I was surprised when it crashed when running it in IDLE after successfully testing on a small subsample. On the full-sized project data, it crashed before successfully creating the first set of contours (1/17) and the result was unfinished (big gaps of contour lines missing).
Just for grins, I turned to the Python window in an open ArcMap session and ran it with the "
execfile" command and lo and behold it is running as I write this up (appears now to be almost done). This screenshot shows that it crashed at the shell and also shows two successful sets of contours in the data frame in the background.
Here is the script:
import arcpy from arcpy import env from arcpy.sa import * # Check out the extension arcpy.CheckOutExtension("Spatial") contourInterval = 2 baseContour = 0 #inputSmthDEM = r"L:\2014\FULL_DEM\WORK\garfmn9" inWorkspace = r"L:\2014\FULL_DEM\WORK\Contours.gdb" outWorkspace = r"L:\2014\FULL_DEM\WORK\Contours.gdb\CONTOURS" env.workspace = inWorkspace rds = arcpy.ListRasters() contourBaseName = "contours_" for rd in rds: clen = len(rd) #cnew = clen - 7 # minus 7 because base name output_ has 7 characters in it # MODIFICATION cnew = clen - 4 # minus 4 because FMN_ has 4 characters in it or minus 2 because G_ has 2 characters etc. # print contourBaseName + str(fc[-cnew:][:-4]) outputName = contourBaseName + str(rd[-cnew:]) # [:-4]) # add a "minus 4" if input are shapefiles but these are rasters Contour(rd, outWorkspace + "\\" + outputName, contourInterval, baseContour)
and here is the error:
Traceback (most recent call last): File "C:\dev\batchContours.py", line 25, in <module> Contour(rd, outWorkspace + "\\" + outputName, contourInterval, baseContour) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 5722, in Contour z_factor) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Utils.py", line 53, in swapper result = wrapper(*args, **kwargs) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\sa\Functions.py", line 5715, in Wrapper z_factor) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\geoprocessing\_base.py", line 504, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Out of memory [contours_1] ERROR 010005: Unable to allocate memory. ERROR 010067: Error in executing grid expression. Failed to execute (Contour).