i have a script that edits sde and requires info or an editor license.
I know that you can use
import arcinfo
or
import arceditor
but if you have two imports, one will fail. So how do you use this pattern to require one or the other?
Thanks in advance for your help.
import arcpy import arcinfo if arcinfo: print 'info license' else: import arceditor if arceditor: print 'editor license'
Wes, this won't work because a license is checked out when arcpy is imported which defaults to highest available (arcinfo if one is available, arceditor if not, or arcview if all else fails). You need to import arcview/arceditor/arcinfo before arcpy.
Like this:
import arceditor import arcpy print arcpy.ProductInfo()
ArcEditor
Not like this:
import arcpy import arceditor print arcpy.ProductInfo()
ArcInfo
Luke thanks i didn't know that. Does that mean then that it should be a try except so if he doesn't get the upper level licenses it won't run?
class LicenseError(Exception): pass import arcpy try: if arcpy.ProductInfo() == 'ArcInfo' or arcpy.ProductInfo() == 'ArcEditor': pass else: # Raise a custom exception # raise LicenseError print 'Do your work here' except LicenseError: print "ArcInfo or ArcEditor license unavailable" except: print arcpy.GetMessages(2)
ok, here is what I wrote up as a standalone check prior to arcpy:
import arcview
if arcview:
print 'arcview license is available'
else:
import arceditor
if arceditor:
print 'arceditor license is available'
else:
import arcinfo
if arcinfo:
print 'arcinfo license is available'
else:
print 'no license is available'
import arcpy
Thanks for this...
Please be aware that a bug has been reported for 10.3 and in 10.3.1 this has still not been fixed. See:
import arceditor does not set proper license level
If you have an older version (like 10.1) it will work (not sure if 10.2 works).
Xander, I'm using 10.2.2 and it works. Did you find a workaround in 10.3?
Still open....
http://support.esri.com/en/bugs/nimbus/role/beta10_1/QlVHLTAwMDA4NDI0Ng==
no posted workaround (except a single use license...which is not an option for some)
As Dan Patterson mentions it is still open en there is no fix available. No workaround unless you want to use single use or separate a license on another server. Thanks for posting that it works in 10.2.2. Apparently it was introduced in 10.3. Might enlist for the 10.4 beta that will soon be around to see if it is fixed...