Im trying to incorporate the Snippets Module on another machine running 10.3.1 I've sucessfully apdapted it to script that uses it with 10.5, along with the comtypes module. However, a machine running a different version of ArcGIS is causing all sorts of headaches

The Snippets module is failing, stating its the version of Arc does not match the one listed in the scriptenter image description here

Here is my code within the Snippets102.py file

def GetLibPath():
    """Return location of ArcGIS type libraries as string"""
    # This will still work on 64-bit machines because Python runs in 32 bit mode
    import _winreg
    keyESRI = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\ESRI\\Desktop Background Geoprocessing (64-bit)")
    return _winreg.QueryValueEx(keyESRI, "InstallDir")[0] + "com\\"

def GetModule(sModuleName):
    """Import ArcGIS module"""
    from comtypes.client import GetModule
    sLibPath = GetLibPath()
    GetModule(sLibPath + sModuleName)

def GetStandaloneModules():
    """Import commonly used ArcGIS libraries for standalone scripts"""

def GetDesktopModules():
    """Import basic ArcGIS Desktop libraries"""

#**** Helper Functions ****

def NewObj(MyClass, MyInterface):
    """Creates a new comtypes POINTER object where\n\
    MyClass is the class to be instantiated,\n\
    MyInterface is the interface to be assigned"""
    from comtypes.client import CreateObject
        ptr = CreateObject(MyClass, interface=MyInterface)
        return ptr
        return None

def CType(obj, interface):
    """Casts obj to interface and returns comtypes POINTER or None"""
        newobj = obj.QueryInterface(interface)
        return newobj
        return None

def CLSID(MyClass):
    """Return CLSID of MyClass as string"""
    return str(MyClass._reg_clsid_)

def InitStandalone():
    """Init standalone ArcGIS license"""
    # Set ArcObjects version
    import comtypes
    from comtypes.client import GetModule
    g = comtypes.GUID("{6FCCEDE0-179D-4D12-B586-58C88D26CA78}")
    GetModule((g, 1, 0))
    import comtypes.gen.ArcGISVersionLib as esriVersion
    import comtypes.gen.esriSystem as esriSystem
    pVM = NewObj(esriVersion.VersionManager, esriVersion.IArcGISVersion)
    if not pVM.LoadVersion(esriVersion.esriArcGISDesktop, "10.3"):
        return False
    # Get license
    pInit = NewObj(esriSystem.AoInitialize, esriSystem.IAoInitialize)
    ProductList = [esriSystem.esriLicenseProductCodeAdvanced, \
                   esriSystem.esriLicenseProductCodeStandard, \
    for eProduct in ProductList:
        licenseStatus = pInit.IsProductCodeAvailable(eProduct)
        if licenseStatus != esriSystem.esriLicenseAvailable:
        licenseStatus = pInit.Initialize(eProduct)
        return (licenseStatus == esriSystem.esriLicenseCheckedOut)
    return False

def GetApp(app="ArcMap"):
    """In a standalone script, retrieves the first app session found.\n\
    app must be 'ArcMap' (default) or 'ArcCatalog'\n\
    Execute GetDesktopModules() first"""
    if not (app == "ArcMap" or app == "ArcCatalog"):
        print "app must be 'ArcMap' or 'ArcCatalog'"
        return None
    import comtypes.gen.esriFramework as esriFramework
    import comtypes.gen.esriArcMapUI as esriArcMapUI
    import comtypes.gen.esriCatalogUI as esriCatalogUI
    pAppROT = NewObj(esriFramework.AppROT, esriFramework.IAppROT)
    iCount = pAppROT.Count
    if iCount == 0:
        return None
    for i in range(iCount):
        pApp = pAppROT.Item(i)
        if app == "ArcCatalog":
            if CType(pApp, esriCatalogUI.IGxApplication):
                return pApp
        if CType(pApp, esriArcMapUI.IMxApplication):
            return pApp
    return None

Registry key referenced -

enter image description here

Anyone experiecne this issue?

As mentioned on another post i've delete the two automation.py and safearray.py compiled scripts within the comtypes site packages. Anyone else experience this issue?

1 Answer 1


You are telling it to load version 10.3, but you have installed version 10.3.1.

My gut tells me that you should be calling this:

pVM.LoadVersion(esriVersion.esriArcGISDesktop, "10.3.1"):

But the best way to find out is to use getVersions first and see what versions are available.

  • Thanks Danielm, Yeah I have tried that, even down to the Product Code with 10.3.4959. Will try to get the getVersions, though will this return a Pointer?
    – Slevy
    Mar 2, 2018 at 1:39
  • I should mention that my ArcObject is limited at best :)
    – Slevy
    Mar 2, 2018 at 1:41
  • @Slevy I could only find Java documentation for this function. If it's equivalent to that it should return an array of IEnumVersions objects. I don't think I've seen anyone use the COM objects so directly in python before, so hopefully it will act similarly.
    – danielm
    Mar 2, 2018 at 15:33
  • Hi Danielm - Yes this seemed to work, though its calling the ArcGIS Server which is installed on the same machine Parsing pVM.GetVersions().next() Returns.. (5, u'10.3', u'C:\\Program Files\\ArcGIS\\Server\\') Is there any way to force change which product it uses?
    – Slevy
    Mar 6, 2018 at 8:36
  • 1
    @Slevy Is that the only version that it returns as you keep subsequently calling next()? That should give you all available versions. In other words a version not listed would not work. Unfortunately, this exhausts my knowledge on the topic.
    – danielm
    Mar 6, 2018 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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