Whenever a tool is executed in a script, an ArcGIS license is required. Tools from ArcGIS extensions, such as the ArcGIS Spatial Analyst, 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.
Extension licenses
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
#
arcpy.CheckInExtension("3D")
In the above example, the ArcGIS 3D Analyst 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:
Extension | Extension Code |
---|---|
ArcGIS 3D Analyst | 3D |
ArcGIS Data Interoperability 10.5.1 for Desktop | DataInteroperability |
ArcGIS Data Reviewer for Desktop | Datareviewer |
ArcGIS for Aviation: Airports | Airports |
ArcGIS for Aviation: Charting | Aeronautical |
ArcGIS for Maritime: Bathymetry | Bathymetry |
ArcGIS for Maritime: Charting | Nautical |
ArcGIS Geostatistical Analyst | GeoStats |
ArcGIS Network Analyst | Network |
ArcGIS Spatial Analyst | Spatial |
ArcGIS Schematics | Schematics |
ArcGIS Tracking Analyst | Tracking |
ArcGIS Workflow Manager for Desktop | JTX |
ArcScan | ArcScan |
Business Analyst | Business |
Esri Defense Mapping | Defense |
Esri Production Mapping | Foundation |
Esri Roads and Highways | Highways |
StreetMap | StreetMap |
Product code names
Product Codes |
---|
ArcView (equivalent to an ArcGIS Desktop Basic license) |
ArcEditor (equivalent to an ArcGIS Desktop Standard license) |
ArcInfo (equivalent to an ArcGIS Desktop Advanced license) |
Engine |
EngineGeoDB |
ArcServer |
Licensing functions
Function | Explanation | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CheckExtension(extension) | Checks to see if a license is available to be checked out for a specific type of extension.
| ||||||||||||||||
CheckInExtension(extension) | Returns the license so other applications can use it.
| ||||||||||||||||
CheckOutExtension(extension) | Retrieves the license.
| ||||||||||||||||
CheckProduct(code) | Checks to see if the requested license is available.
| ||||||||||||||||
ProductInfo() | Returns the current product license.
| ||||||||||||||||
SetProduct(code) | Defines the desktop license.
|