简体   繁体   中英

importing pywinauto.application throws error while trying to run using python 3.5.4

I was trying to execute the following command on windows 10 machine using python 3.5.4,

from pywinauto.application import Application

Following is the error which i was receiving

Traceback (most recent call last):
  File "C:/Users/bizact/Desktop/PSAV/test.py", line 1, in <module>
    from pywinauto.application import Application
  File "C:\Program Files\Python35\lib\site-packages\pywinauto\__init__.py", line 72, in <module>
    from . import findwindows
  File "C:\Program Files\Python35\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "C:\Program Files\Python35\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:\Program Files\Python35\lib\site-packages\pywinauto\controls\uiawrapper.py", line 46, in <module>
    from ..uia_defines import IUIA
  File "C:\Program Files\Python35\lib\site-packages\pywinauto\uia_defines.py", line 35, in <module>
    import comtypes.client
  File "C:\Program Files\Python35\lib\site-packages\comtypes\client\__init__.py", line 33, in <module>
    gen_dir = _find_gen_dir()
  File "C:\Program Files\Python35\lib\site-packages\comtypes\client\_code_cache.py", line 71, in _find_gen_dir
    result = os.path.abspath(gen_path[-1])
IndexError: list index out of range

Is there a way i can fix this ?

Try running the script with administrative privileges. Just by looking at the traceback it looks like some cached files that pywinauto import tried to write but later on it wasn't found, and generally the script can't write the file due to permissions. If the above don't work, try installing python somewhere else (C:/Python with full privileges in order to isolate the issue)

This is comtypes issue. It will be fixed soon (EDIT: fixed in comtypes==1.1.7 ). You can downgrade to one of previous versions: pip install comtypes==1.1.2 . Or run script as Administrator as Rodolfo suggested (disabling UAC may not help, need to say explicitly to "run as Administrator" by popup menu).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM