Python restarts when spatial analyst tools are used--help!!

1618
3
12-19-2013 07:00 PM
GraceWu
New Contributor
I'm running geoprocessing scripts in IDLE and everything runs exactly as expected until it comes to a function that requires the spatial analyst module. the cost path or zonal statistics tools cause Python to restart immediately (and the Command window to close), without reporting an error. I've ran my script successfully before, but I very recently started to encounter this (bug?) in implementing the script. I've tried to repair ArcGIS 10.2, reinstall it, uninstall it and reinstall 10.1. I've also tried downloading a new version of Python 2.7.6 and added the libraries to get arcpy to import. Again, the script runs until it hits a spatial analyst tool. I've also tried arcpy.sa.ZonalStatisticsAsTable() command in addition to adding "from arcpy.sa import * ." The former worked a couple of times in the Python command window and then it suddenly stopped working. However, running the exact same spatial analyst tools with the exact same inputs in ArcMap works perfectly well. Does anyone have any suggestions for what could be wrong? a bug?  I've written my entire model to run in python and now it doesn't work anymore. HELP!
0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor
Have you installed 64-bit background geoprocessing? If you have, you may be running into some of the limitations of 64 bit arcpy. (If you run models in "edit" mode, all processes run in the ArcMap foreground, which is always 32-bit arcpy.)

If you have installed background GP, the last Python installed is 64-bit, so that's the one that comes up when you start up IDLE:
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 


The fix is to start 32-bit IDLE by making a copy of the shortcut and modifying its start up from

C:\Python27\ArcGISx6410.2\pythonw.exe "C:\Python27\ArcGISx6410.2\Lib\idlelib\idle.pyw"


to

C:\Python27\ArcGIS10.2\pythonw.exe "C:\Python27\ArcGIS10.2\Lib\idlelib\idle.pyw"
0 Kudos
GraceWu
New Contributor
Thanks for the reply! It looks like I am/have been running 32 bit python (Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32). I ran the script a few times trying to catch the error message that flashes for half a second before the command window closes and it says something like "FATAL ERROR (INDEF) \n directory full" I don't know what directory the message is referring to, but i'm not limited in disk space...any ideas?

I also tried changing the following script, which, unmodified, runs perfectly fine in ArcMap:
arcpy.sa.ZonalStatisticsAsTable(inFeatureRaster, zoneField_RQ, inValueRaster_RQ, workspace + inFeatureProjects + "_ZonalStatsTable_RQ", "NODATA", "MEAN")

to a non-existent zone field, and it threw an error as expected:
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000864: Zone field: The input is not within the defined domain.
ERROR 000889: Invalid field type.
Failed to execute (ZonalStatisticsAsTable).

so it looks like python is calling on the right SA functions. Now i'm just seriously confused.
0 Kudos
curtvprice
MVP Esteemed Contributor
Thanks for the reply! It looks like I am/have been running 32 bit python (Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32). I ran the script a few times trying to catch the error message that flashes for half a second before the command window closes and it says something like "FATAL ERROR (INDEF) \n directory full" I don't know what directory the message is referring to, but i'm not limited in disk space...any ideas?


A clue! That's a low level error from the raster engine.

Have you set your geoprocessing scratch workspace? My guess is the one you have set (or the one you are defaulting to) is either full -- or you cannot write grids to it for another reason. (For example, it has a corrupted "info" folder, you don't have system write access, or it's a corrupted geodatabase.)

I bet your problem is the current folder is being used as the scratch workspace, which will not work if you are starting your Python script from a folder to which you cannot write. In ArcMap, things are working because you have set the environment workspace there at the application level (geoprocessing > environments).

I suggest setting the scratch and current workspace to the same location (best practice for raster processing!) and seeing if that helps you out.

Using the current workspace settings can save you a lot of complex path construction, everything is assumed to read and write from the current workspace.

import os
outRaster = r"C:\my_writeable_folder\outgrid"
arcpy.env.workspace = arcpy.env.scratchWorkspace = os.path.dirname(outRaster)
arcpy.sa.ZonalStatisticsAsTable(�?�)
0 Kudos