Select to view content in your preferred language

Why does GetInstallInfo('desktop') return info for Engine?

4374
5
02-11-2015 06:19 AM
JohnLovato
Occasional Contributor

When both engine and desktop 10.2 are installed on the same machine.  GetInstallInfo('desktop') returns information for the engine install.  See the sample code below.

CodeOutput

import arcinfo

import arcpy

arcpy.SetProduct('ArcInfo')

for install in arcpy.ListInstallations():

    print('\nINFO: for ' + install + ' installation')

    # Use the dictionary iteritems to iterate through

    #   the key/value pairs from GetInstallInfo

    d = arcpy.GetInstallInfo(install)

    for key, value in d.iteritems():

        # Print a formatted string of the install key and its value

        #

        print("{:<13} : {}".format(key, value))

INFO: for desktop installation

SourceDir     : ...\ESRI\ArcGIS10.2.2\Engine\windows\SetupFiles\

InstallDate   : 7/28/2014

InstallDir    : c:\arcgis\engine10.2\

ProductName   : Engine

BuildNumber   : 3552

InstallType   : Typical

Version       : 10.2.2

SPNumber      : N/A

Installer     : install_user

SPBuild       : N/A

InstallTime   : 12:48:48

INFO: for engine installation

SourceDir     : ...\ESRI\ArcGIS10.2.2\Engine\windows\SetupFiles\

InstallDate   : 7/28/2014

InstallDir    : c:\arcgis\engine10.2\

ProductName   : Engine

BuildNumber   : 3552

InstallType   : Typical

Version       : 10.2.2

SPNumber      : N/A

Installer     : install_user

SPBuild       : N/A

InstallTime   : 12:48:48

Tags (2)
0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

The GetInstallInfo (arcpy) does not use the provided parameter. See the help:

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

In my ase it returns this output (twice the same info):

INFO: for desktop installation
SourceDir    : C:\Users\xbakker\Documents\ArcGIS 10.3\Desktop\SetupFiles\
InstallDate  : 2014/12/16
InstallDir    : c:\program files (x86)\arcgis\desktop10.3\
ProductName  : Desktop
BuildNumber  : 4322
InstallType  : N/A
Version      : 10.3
SPNumber      : N/A
Installer    : xbakker
SPBuild      : N/A
InstallTime  : 16:07:59


INFO: for explorer installation
SourceDir    : C:\Users\xbakker\Documents\ArcGIS 10.3\Desktop\SetupFiles\
InstallDate  : 2014/12/16
InstallDir    : c:\program files (x86)\arcgis\desktop10.3\
ProductName  : Desktop
BuildNumber  : 4322
InstallType  : N/A
Version      : 10.3
SPNumber      : N/A
Installer    : xbakker
SPBuild      : N/A
InstallTime  : 16:07:59

BTW:  you can remove the line:

arcpy.SetProduct('ArcInfo')

This does not do anything, since the license level is determined when you import arcpy or as you do with setting the license level using the import arcinfo. Note that in 10.3 there is a bug and it you cannot set the license level from a stand alone script, it will simply consume the highest license available...

0 Kudos
JohnLovato
Occasional Contributor

Xander,

  What method should be used to return only  desktop installation directory?  The developer used GetInstallInfo()[InstallDir] in the past, but that won't work when both engine and desktop are on the same machine.

Regards,

John P. Lovato

0 Kudos
XanderBakker
Esri Esteemed Contributor

The alternative could be looking at the path settings:

import sys
for p in sys.path:
    p = p.lower()
    if "arcgis\\desktop" in p and p.endswith('bin'):
        print p
0 Kudos
JohnLovato
Occasional Contributor

Thank you Xander.  I'll see if this will work for the developer.  It looks like it gives the correct information for me.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

There are a couple of things going on here.  First, arcpy.GetInstallInfo has no parameters.  It will accept an argument and not throw an error, but any argument that is passed doesn't affect the results of what is returned.  The arcpy.GetInstallInfo function gets the installation information that relates to the currently loaded ArcPy site package, which in your case is ArcGIS Engine.

If you install ArcGIS Desktop and ArcGIS Engine on the same machine using standard installation instructions, the two will share a single Python interpreter, usually C:\Python27\ArcGIS10.x (10.2 in this case).  Another way to look at it is that a single Python interpreter has 2 ArcPy site packages registered/installed.  Since the site packages have the same name (arcpy), they both can't be loaded into the interpreter at the same time.  When the interpreter encounters an import arcpy statement, it will find and import whichever site package is found first in the search path for modules, i.e., sys.path.

Before importing ArcPy, you can quickly determine which ArcPy site package will be loaded by running:

import imp
imp.find_module('arcpy')

In this case, the result will come back with ...\Engine10.2\... since it comes first in the sys.path.  Reversing the order of sys.path before importing ArcPy will likely find and import the Desktop site package for your situation.

import imp
import sys
sys.path.reverse()
imp.find_module('arcpy')

The issue with reversing sys.path out of hand is that it will import the Engine-based site package if ArcGIS Engine was installed first.  There are a couple of more thoughtful ways to get around this problem.  First, setting the PYTHONPATH Windows environment variable to the Desktop-based site package will ensure that it is loaded first regardless of the sys.path order.  However, in this case, it seems you don't already know that location and am trying to figure it out.  A second approach would be to remove all of the Engine-related entries in sys.path before import arcpy.

import sys
for p in sys.path[:]:
    if 'Engine' in p:
        sys.path.remove(p)

If the goal is to determine whether ArcGIS Desktop is installed and where, maybe querying a WMI service for installed applications and information is a better approach.  Adapted from the Microsoft Script Center List Installed Software Python script:

import win32com.client 
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") 
objSWbemServices = objWMIService.ConnectServer(".", "root\cimv2") 
colItems = objSWbemServices.ExecQuery("Select * from Win32_Product "
                                      "where Name Like 'ArcGIS % for Desktop'") 
for objItem in colItems: 
    print "Name: ", objItem.Name 
    print "Install Date: ", objItem.InstallDate 
    print "Install Location: ", objItem.InstallLocation
    print ""