Whenever a tool is executed in a script, an ArcGIS license is required. Tools from ArcGIS extensions, such as the ArcGIS Spatial Analyst extension, require an additional license for that extension. If the necessary licenses are not available, a tool fails and returns error messages. For example, if you install with an ArcGIS Desktop Basic license, and you attempt to execute a tool that requires a Desktop Standard or Desktop Advanced license, the tool will fail.
When using an ArcGIS Desktop Basic or Desktop Standard license, a script should set the product to Desktop Basic or Desktop Standard. Likewise, when using an Engine or EngineGeoDB license, a script should set the product to Engine or EngineGeoDB. If a license is not explicitly set, the license will be initialized based on the highest available license level the first time an ArcPy tool, function, or class is accessed.
Every tool checks to ensure it has the appropriate license. If it doesn't have what's required, it fails. To guard against the situation of executing partially through and failing, you can perform a check at the top of your script and fail immediately.
Desktop, Engine/Server licenses
Product modules are imported prior to the import of arcpy to define the desktop license used by a script. The CheckProduct function can be used to check the availability of desktop licenses, while the ProductInfo function reports what the current product license is.
Licenses for extensions can be retrieved from a license manager and returned once they are no longer needed. CheckExtension is used to see if a license is available to be checked out for a specific type of extension, while CheckOutExtension actually retrieves the license. Once the extension license has been retrieved by the script, extension tools can be executed. Once a script is done using tools from a particular extension, the CheckInExtension function should be used to return the license to the license manager so other applications can use it. All checked-out extension licenses and set product licenses are returned to the license manager when a script completes.
The following example executes some ArcGIS 3D Analyst tools and sets the desktop product license to ArcGIS Desktop Basic, since an ArcGIS Desktop Advanced license is not required to execute tools from an extension. The script will fail if the ArcGIS Desktop Basic license is not explicitly set and no ArcGIS Desktop Advanced license is available, since a desktop license is required to execute extension tools.
class LicenseError(Exception): pass # Set desktop license used to Basic (keyword is arcview) # import arcview import arcpy try: if arcpy.CheckExtension("3D") == "Available": arcpy.CheckOutExtension("3D") else: # Raise a custom exception # raise LicenseError arcpy.env.workspace = "D:/GrosMorne" arcpy.HillShade_3d("WesternBrook", "westbrook_hill", 300) arcpy.Aspect_3d("WesternBrook", "westbrook_aspect") except LicenseError: print("3D Analyst license is unavailable") except arcpy.ExecuteError: print(arcpy.GetMessages(2)) finally: # Check in the ArcGIS 3D Analyst extension # arcpy.CheckInExtension("3D")
In the above example, the ArcGIS 3D Analyst extension is checked in under a finally clause, ensuring that the extension is always checked back in, whether an exception has occurred or not.
A returned value of Failed, Unavailable, or NotLicensed indicates that the extension could not be successfully checked out.
Below are the extension names and their extension code names:
ArcGIS 3D Analyst extension
ArcGIS Data Interoperability extension for Desktop
ArcGIS Data Reviewer for Desktop
ArcGIS for Aviation: Airports
ArcGIS for Aviation: Charting
ArcGIS for Maritime: Bathymetry
ArcGIS for Maritime: Charting
ArcGIS Geostatistical Analyst extension
ArcGIS Network Analyst extension
ArcGIS Spatial Analyst extension
ArcGIS Schematics extension
ArcGIS Tracking Analyst extension
ArcGIS Workflow Manager for Desktop
Esri Defense Mapping
Esri Production Mapping
Esri Roads and Highways
Product code names
ArcView (equivalent to an ArcGIS Desktop Basic license)
ArcEditor (equivalent to an ArcGIS Desktop Standard license)
ArcInfo (equivalent to an ArcGIS Desktop Advanced license)
Checks to see if a license is available to be checked out for a specific type of extension.
Returns the license so other applications can use it.
Retrieves the license.
Checks to see if the requested license is available.
Returns the current product license.
Defines the desktop license.