Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yinkaisheng opened this issue Feb 13, 2020 · 6 comments
Closed
Labels
wontfix This will not be worked on

Comments

@yinkaisheng
Copy link

yinkaisheng commented Feb 13, 2020

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.

@vasily-v-ryabov
Copy link
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.

@vasily-v-ryabov vasily-v-ryabov added the wontfix This will not be worked on label Feb 13, 2020
@yinkaisheng
Copy link
Author

Thanks.

@Wang-zhipeng
Copy link

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'

@vasily-v-ryabov
Copy link
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.

@yixue99
Copy link

yixue99 commented Aug 15, 2021

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

@junkmd
Copy link
Collaborator

junkmd commented Feb 4, 2024

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
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants