pywinauto / pywinauto

Windows GUI Automation with Python (based on text properties)
http://pywinauto.github.io/
BSD 3-Clause "New" or "Revised" License
4.94k stars 688 forks source link

Incompatibility to comtypes version 1.1.8 #1034

Open m-rossi opened 3 years ago

m-rossi commented 3 years ago

Expected Behavior

As documented in https://github.com/conda-forge/pywinauto-feedstock/issues/11 and https://github.com/enthought/comtypes/issues/222

import pywinauto

fails when comtypes 1.1.8 is installed. A downgrade to 1.1.7 fixes the issue. I added a version constraint in the conda-forge-recipe https://github.com/conda-forge/pywinauto-feedstock/blob/1a4d91fc9e71b66f274c453b320a8c8de41baf4e/recipe/meta.yaml

Actual Behavior

import: 'pywinauto'
Traceback (most recent call last):
  File "D:\bld\pywinauto_1611080599318\test_tmp\run_test.py", line 2, in <module>
    import pywinauto
   File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\__init__.py", line 89, in <module>
    from . import findwindows
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
    from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
    from ..uia_defines import IUIA
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\comtypes\client\_generate.py", line 118, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\comtypes\client\_generate.py", line 183, in _CreateWrapper
    generate_module(tlib, ofi, pathname)
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module
    gen.generate_code(list(items.values()), filename=pathname)
  File "D:\bld\pywinauto_1611080599318\_test_env\lib\site-packages\comtypes\tools\codegenerator.py", line 261, in generate_code
    tlib_mtime = os.stat(self.filename).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'UIAutomationCore.dll'

Steps to Reproduce the Problem

  1. Install or update to comtypes 1.1.8

Specifications

Mertica commented 3 years ago

Same issue here - using pip install comtypes==1.1.7 solves it for now

vasily-v-ryabov commented 3 years ago

Fixed in comtypes==1.1.9.

Whiskas101 commented 4 months ago

It still throws the same exception with comtypes==1.1.9

junkmd commented 4 months ago

@Whiskas101

As the maintainer of comtypes, I found this.

Does this also occur with the latest version, comtypes==1.4.4?

Additionally, the native codebase of comtypes was Python 2 up to version 1.1.11. As reported in https://github.com/enthought/comtypes/issues/251, the native codebase was converted to Python 3 following the drop of the 2to3 conversion.

The fact that comtypes==1.1.9 did not result in a SyntaxError but ran for a moment, even if it resulted in another error, suggests that there might be something special about your environment.

Please provide the traceback and the Python version.

If this issue can also occur with the latest comtypes, I would be happy to help with the fix.

In any case, since I cannot reproduce the issue in my environment, I feel that your cooperation is necessary to resolve the problem.

Whiskas101 commented 4 months ago

It does not occur with 1.4.4, that's what I am currently using. I'll provide the details you asked for when I get back home to my PC.