The tool is not licensed

3395
9
Jump to solution
11-09-2020 04:47 PM
Arthur_Morgan
New Contributor III

Hi I am trying to run the following script from py 2.7 IDLE that comes with ArcMap 10.7.1. When I try to run the following script:

import arcpy
import os
from arcpy import env
from arcpy.sa import *
#Set the evironment settings
arcpy.env.workspace = r'D:\Spring2020\VIC\PCA_Reclass_2004\PCA_Reclass_04'
#Load the rasters
folder = r'D:\Spring2020\VIC\PCA_Reclass_2004\PCA_Reclass_04'
rasters = arcpy.ListRasters("*","TIF")
print rasters
inpoly = r'D:\Spring2020\VIC\EB_Correct_File_ArcGIS\VIC.shp'
out = r'D:\Spring2020\VIC\EB_Correct_File_ArcGIS'
print([field.name for field in arcpy.ListFields(inpoly)])
cursor= arcpy.SearchCursor(inpoly,['GRID_CODE'])
print cursor
with arcpy.da.SearchCursor(inpoly,['GRID_CODE']) as cursor:
 for row in cursor:
    #print row
    for raster in rasters:
    out = os.path.join(out, raster + ".dbf")
    outT= arcpy.gp.ZonalStatisticsAsTable(inpoly,"GRID_CODE",raster, out, "DATA",'MEAN') 

I get the following error (even though I have the license and can use the tool in ArcMap):
raceback (most recent call last):
 File "D:/Spring2020/VIC/zonal_stats_Table.py", line 21, in <module>
 outT= arcpy.gp.ZonalStatisticsAsTable(inpoly,"GRID_CODE",raster, out, "DATA",'MEAN')
 File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
 return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000824: The tool is not licensed.
Failed to execute (ZonalStatisticsAsTable).
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Checking whether Spatial is available is the first step, next you need to call CheckOutExtension—ArcMap | Documentation .  The example code in the documentation gives you the steps you need to follow.

View solution in original post

9 Replies
JoshuaBixby
MVP Esteemed Contributor

Have you tried checking out a Spatial Analyst license to use the tool? CheckOutExtension—ArcMap | Documentation 

Arthur_Morgan
New Contributor III

Yes it says Zonal Statistics As Table is unavailable, I tried the following:

if arcpy.CheckExtension("ZonalStatisticsAsTable")=="Available":
   arcpy.CheckOutExtension("ZonalStatisticsAsTable"

else:

print "Zonal Statistics As Table is unavailable"

0 Kudos
Arthur_Morgan
New Contributor III

But this is not be happening as I have the license and I even use the tool in ArcMap

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

ZonalStatistics isn't a extension, it is a tool, and CheckOutExtension is for licensing extensions.  You need to know what license is required for your tool, which is why I asked about Spatial Analyst (use "Spatial") because that is the license you will need.

Arthur_Morgan
New Contributor III

I tried the following and based on the print, it does say that Spatial Analyst is available.

#Check the license
if arcpy.CheckExtension("Spatial")=="Available":
   print "Spatial is available"
else:
   print "Zonal Statistics As Table is unavailable"

Output

Spatial is available

0 Kudos
by Anonymous User
Not applicable

Hey Saad!  This is far from my area of expertise but I think you may want to actually include a line within your script to checkout the license.  A colleague and I have seen this error before and it looks like including a line to check out the license (for example. arcpy.CheckOutExtension("Spatial") may be needed.  Hopefully that helps guide you along to the right path!  Perhaps others can help chime in.

0 Kudos
Arthur_Morgan
New Contributor III

Hi Will, thank you for your response, and as you suggested, I did the exact same thing and it prints Spatial is available, please see below:

#Check the license
if arcpy.CheckExtension("Spatial")=="Available":
   print "Spatial is available"
else:
   print "Zonal Statistics As Table is unavailable"

Output

Spatial is available

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Checking whether Spatial is available is the first step, next you need to call CheckOutExtension—ArcMap | Documentation .  The example code in the documentation gives you the steps you need to follow.

Arthur_Morgan
New Contributor III

I tried the steps as mentioned in the mentioned and it worked, thank you!

0 Kudos