Select to view content in your preferred language

Error in executing grid expression.

4318
3
Jump to solution
12-20-2014 12:48 AM
AhsanAbbas
Deactivated User

Every time i run the script i got error "Error executing the grid expression, run time error, Failed to execute (Slope). " ? What is wrong with in code ?

When i run the Slope tool in ArcGIS it's give me the same error, but when i run the script in ArcGIS python Command prompt it runs successfully what is the problem, i don't understands ?

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "......."

if arcpy.CheckExtension("spatial") == "Available":
     arcpy.CheckOutExtension("spatial")
     outraster = arcpy.sa.Slope("elevation", "PERCENT_RISE")
     outraster.save("slope_per")
     arcpy.CheckInExtension("spatial")
else:
     print "Spatial Analyst Liscence is not avaliable"

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

If you are in arcmap, go to the Customize menu, select Extensions and toggle on the spatial analyst extension.  If you are running from a script, this line needs to have spatial capitalized

if arcpy.CheckExtension("spatial") == "Available":    should be

if arcpy.CheckExtension("Spatial") == "Available":

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

from arcpy.sa import *

this line is run before the availability of the extension is made.  The arcmap python command line is a different beast...try not to use it, use an external python IDE to test command line code

0 Kudos
AhsanAbbas
Deactivated User

I get these error messages

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000824: The tool is not licensed.

Failed to execute (Slope).

every time i run the tool from arcgis and specify the folder for output result it gives me same error, but when i save it in result gdb it's run sucessfully ? what is the reason i don't understands ?

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you are in arcmap, go to the Customize menu, select Extensions and toggle on the spatial analyst extension.  If you are running from a script, this line needs to have spatial capitalized

if arcpy.CheckExtension("spatial") == "Available":    should be

if arcpy.CheckExtension("Spatial") == "Available":