3

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.

enter image description here

Script Running Fine from Python Window

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

My Geoprocessing Options:
My GeoProcessing Options

  • 2
    Do you have 64-bit Background Geoprocessing installed? If so, are you using the 64-bit IDLE? – Vince Jun 3 '16 at 18:06
  • No. I did not install anything other than 10.3.1. I assumed that bg geoprocessing would be installed with that since bg geoprocessing came out when 10.1 was the latest, but after your comment, I researched this and it appears it is still a separate download. – jbchurchill Jun 5 '16 at 17:28
1

Disable background processing. (Uncheck the "Enable" option in background processing)

This causes an incredible amount of problems for me when processing contours.

That should eliminate error 010005

  • 1
    From my reading of the Question the background processing and running within ArcMap is working fine, so disabling that won't solve the issue of it crashing in IDLE. – Midavalo Jun 3 '16 at 19:54
  • That is correct Midavalo! Thanks for the advice though. I'm not sure how those ArcMap settings affect the python scripts running in IDLE but I'm assuming they do not. – jbchurchill Jun 5 '16 at 17:23

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.