7

Is there a way to check with arcpy whether or not a specific ArcGIS for Desktop service pack is installed on the local machine?

More specifically, my script can only work with ArcGIS 10.1 with SP1 or higher versions. In case of earlier versions, I want to display a message to the user and stop the script before it crashes.

10

Try

arcpy.GetInstallInfo()

You'll get a dictionary of keys and should be able to write some logic on that

{'SourceDir': u'C:\Users\kevi5105\Documents\ArcGIS 10.3\Desktop\SetupFiles\', 'InstallDate': u'5/5/2015', 'InstallDir': u'c:\program files (x86)\arcgis\desktop10.3\', 'ProductName': u'Desktop', 'BuildNumber': u'4322', 'InstallType': u'N/A', 'Version': u'10.3', 'SPNumber': u'N/A', 'Installer': u'kevin5', 'SPBuild': u'N/A', 'InstallTime': u'10:19:54'}

So, logic might be like:

try:
    ver = float(arcpy.GetInstallInfo()['Version'])
except:
    ver = 10.0    
try:
    sp = float(arcpy.GetInstallInfo()['SPNumber'])
except:
    sp = 0

if ver >= 10.1 and sp > 1:
  #do something

(I'm guessing at the SP # at 10.1... you may have to correct it)

  • Treating version numbers as floats is generally a bad idea. Consider 10.2 vs. 10.10. Granted ESRI doesn't seem to have minor version numbers that high, but as a general principle, it's just a bad idea. You'd be better off to do ver = tuple(int(i) for i in arcpy.GetInstallInfo()['Version'].split('.')). Then you specify your check later as ver >= (10, 1). This will compare as expected, even for minor version numbers as high as 10.10. – jpmc26 Nov 10 '15 at 0:49
  • I understand what you're saying, and maybe in general that is a good practice, but with the Esri versions, this will work for everything released and continue to long into the future. We actually long the versions in our test harness and have look up tables (so we end up with values like 1005 or 1031). So whether you float, long, or tuple, they'll all work. – KHibma Nov 10 '15 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.