question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot import pywinauto in python 3.7 64bit ( works on 32 bit)!!!

See original GitHub issue

Problem

I want to use pywinauto for 64-bit game automation. I got stuck at calling the function print_control_identifiers() when using python 32bit.

import pyautogui 
import psutil
import pywinauto
from pywinauto.application import Application
#global var
processid = 0
handle = pywinauto.findwindows.find_window(best_match='fifa')
app = pywinauto.application.Application().connect(handle=handle)
windows = app.windows()
fo4_window = app.window(title='FIFA ONLINE 4')
fo4_window.print_control_identifiers()

variables at break point before error: image

errror:

 
C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py:1091: UserWarning: 64-bit application should
be automated using 64-bit Python (you use 32-bit Python)
  UserWarning)
C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py:1010: UserWarning: Python process has no rights to make changes in the target GUI (run the script as Administrator)
  warnings.warn(warning_text, UserWarning)
Control Identifiers:
Traceback (most recent call last):
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
    run()
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\Offline Study\fo4_automation\run.py", line 15, in <module>
    fo4_window.print_control_identifiers()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py", line 689, in print_control_identifiers
    print_identifiers([this_ctrl, ])
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\application.py", line 660, in print_identifiers
    if hasattr(ctrl.element_info, 'automation_id'):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\win32_element_info.py", line 201, in automation_id
    remote_mem = RemoteMemoryBlock(self, size=length*2)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pywinauto\remote_memory_block.py", line 96, in __init__
    process_id)
pywinauto.remote_memory_block.AccessDenied: ('[WinError 5] Access is denied.process: %d', 1604)

When I switched to python 64-bit, I even couldn’t import pywinauto ( already installed again with pip 64 bit)

Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\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 "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
    run()
  File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\Offline Study\fo4_automation\run.py", line 7, in <module>
    import pywinauto
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\__init__.py", line 89, in <module>
    from . import findwindows
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\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 "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
    from ..uia_defines import IUIA
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\gen\_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py", line 1002, in <module>
    ( ['out', 'retval'], POINTER(POINTER(IUIAutomationElement)), 'element' )),
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
    self._make_methods(value)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\Admin\AppData\Local\Programs\Python\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.

Hope to receive your answers

Specifications

  • Pywinauto version:0.6.8
  • Python version and bitness: 3.7 64bit
  • Platform and OS: Windows 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eavictorcommented, Aug 14, 2020

For other people who have dependencies in their project blocking upgrade to python 3.8.2 or later.

Python 3.7.8 64bit (Windows 10 20H1) also works.

1reaction
vasily-v-ryabovcommented, Dec 25, 2019

Sorry, for this case it’s almost proper use except you don’t have to use find_windows, but you need connect(title="..."). Also you need 64-bit Python for 64-bit process if you’re using default Application(backend="win32"). Using backend="uia" doesn’t require 64-bit Python, but the hierarchy will be completely different and more detailed for some apps.

Just try earlier version of 64-bit Python or try Application(backend="uia") as a conclusion.

P.S. We may need to add more proper error message for the first case on 32-bit Python.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot import pywinauto on Windows 10 - Stack Overflow
I have the same issue today and fixed it by pip install comtypes==1.1.7 . It caused by comtypes library which release a new...
Read more >
pywinauto Documentation - Read the Docs
sysinfo module for checking 32-bit or 64-bit OS and Python. • set_foreground flag in TypeKeys method for typing into in-place controls.
Read more >
What is pywinauto — pywinauto 0.6.8 documentation
pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and...
Read more >
winreg — Windows registry access — Python 3.11.1 ...
Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. On 32-bit Windows, this constant is ignored. winreg.KEY_WOW64_32KEY¶.
Read more >
pywinauto/pywinauto - Gitter
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe ... and the python console works ok when i state from pywinauto import Application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found