Skip to content

comtypes.client.GetModule("UIAutomationCore.dll") failed in python 3.7.6 #202

Closed

Description

@yinkaisheng

It worked in 3.7.3, but failed in 3.7.6.

Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 18 2019, 23:46:00) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import comtypes
import comtypes.client
comtypes.client.GetModule("UIAutomationCore.dll")

Traceback (most recent call last):
File "D:\Python37\lib\ctypes_init_.py", line 121, in WINFUNCTYPE
return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.LP_POINTER(IUIAutomationCondition)'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "D:\Python37\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "D:\Python37\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper
mod = _my_import(fullname)
File "D:\Python37\lib\site-packages\comtypes\client_generate.py", line 24, in my_import
return import(fullname, globals(), locals(), ['DUMMY'])
File "D:\Python37\lib\site-packages\comtypes\gen_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py", line 1244, in
( ['out', 'retval'], POINTER(POINTER(IUIAutomationElement)), 'element' )),
File "D:\Python37\lib\site-packages\comtypes_init
.py", line 329, in setattr
self.make_methods(value)
File "D:\Python37\lib\site-packages\comtypes_init
.py", line 698, in make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File "D:\Python37\lib\ctypes_init
.py", line 123, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 2 in argtypes passes a union by value, which is unsupported.

Activity

  1. vasily-v-ryabov commented on Feb 13, 2020

    @vasily-v-ryabov
    Collaborator

    This is wrong fix in Python 3.7.6 and 3.8.1. This is already reverted in Python (3.8.2rc1 is in validation now, so there is a hope to release Python 3.8.2 where it should work). Now just install earlier Python version.

    The core of the problem is a missing feature in libffi (this is calling convention handling library used by ctypes for Python/C integration). But this feature is unlikely to be implemented soon.

  2. added
    wontfix
    on Feb 13, 2020
  3. yinkaisheng commented on Feb 14, 2020

    @yinkaisheng
    Author

    Thanks.

  4. Wang-zhipeng commented on Jul 13, 2020

    @Wang-zhipeng

    I also have the problem:
    when I execute .py, everything works well, but I use pyinstaller(3.6) build to exe, and run exe on another system that has no python environment, error occured. my python version 3.7.2
    Traceback (most recent call last):
    File "run.py", line 73, in main
    File "Test_Suite\multiple_display_wes.py", line 99, in start
    File "Common\vdi_connection.py", line 79, in wrapper
    File "Common\vdi_connection.py", line 657, in logon
    File "Common\vdi_connection.py", line 641, in close_citrix
    File "site-packages\uiautomation\uiautomation.py", line 5860, in Exists
    File "site-packages\uiautomation\uiautomation.py", line 7683, in FindControl
    File "site-packages\uiautomation\uiautomation.py", line 7465, in GetRootControl
    File "site-packages\uiautomation\uiautomation.py", line 51, in instance
    File "site-packages\uiautomation\uiautomation.py", line 56, in init
    File "site-packages\comtypes\client_generate.py", line 110, in GetModule
    File "site-packages\comtypes\client_generate.py", line 172, in _CreateWrapper
    File "site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module
    File "site-packages\comtypes\tools\codegenerator.py", line 241, in generate_code
    File "site-packages\comtypes\tools\codegenerator.py", line 189, in generate_all
    File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
    File "site-packages\comtypes\tools\codegenerator.py", line 701, in ComInterface
    File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
    File "site-packages\comtypes\tools\codegenerator.py", line 722, in ComInterfaceHead
    File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
    File "site-packages\comtypes\tools\codegenerator.py", line 722, in ComInterfaceHead
    File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
    File "site-packages\comtypes\tools\codegenerator.py", line 629, in External
    File "site-packages\comtypes\client_generate.py", line 110, in GetModule
    File "site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper
    File "site-packages\comtypes\client_generate.py", line 24, in _my_import
    ModuleNotFoundError: No module named 'comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0'

  5. vasily-v-ryabov commented on Jul 22, 2020

    @vasily-v-ryabov
    Collaborator

    Hi @Wang-zhipeng this is completely different problem. First you need to know that comtypes generates Python code for UIAutomationCore.dll on the fly and saves it to cached .py file which is missing in your case (_00020430_0000_0000_C000_000000000046_0_2_0.py). The file name contains GUID of the COM library. You need some trick with PyInstaller to include this cached file into your executable.

  6. yixue99 commented on Aug 15, 2021

    @yixue99

    I use pyinstaller build to exe, and run exe on another system that has no python environment, it can't run. my python version 3.9.4,UIAutomation version 2.0.15

  7. junkmd commented on Feb 4, 2024

    @junkmd
    Collaborator

    Note:
    reported in python/cpython#16799, resolved (reverted) in python/cpython#17960,
    and fixed in Python 3.7.7 and 3.8.2.

    From python/cpython#16799 (comment)

    The reverting change was committed on Jan 12, 2020. Python versions 3.7.7 (released Mar 10, 2020) and 3.8.2 (released Feb 24, 2020) should have the reversion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions