Open korniichuk opened 6 years ago
I have the same environment, at least for the packages listed above. I first use virtual environment and get the same error. Then I switch back the original environment and get my exe work. Are you using anacondas? May be add ” --hidden-import=comtypes “ in the setup file. An other strange thing is if I switch back to the virtual environment but keep the same pycache folder, my script also works.
I have the same problem, and I am not using anacondas (I don't know what it is). I tried "--hidden-import=comtypes" and it does not help.
Environment: Windows 10 Python 2.7.14 PyInstaller 3.3.1 pywinauto 0.6.3 comtypes 1.1.4
Thank you very much for any help!
Anacondas contains lots of common packages with Python. I use it to build exe, and I always get it work, thought the size is really LARGE ( usually include pyqt, numpy,mkl , etc). I have no knowledge on tech details, but I guess when a program gets built, python will write some compiled files, including comtype, in pycache (not generated by pyinstaller). Then when you build the second time, pyinstaller will find the codes.
@yu45020 thanks for your comment. PyInstaller does not work with Pywinauto. Python 3.6.4 and Python 2.7.14. With Anaconda and w/o Anaconda. With and w/o --hidden-import=comtypes
. py2exe works with Pywinauto and Python 2.7.14 as well, but I can not create a one-file bundled executable with py2exe.
This looks like File "site-packages\comtypes\client_generate.py", line 169, in _CreateWrapper tries to open a file (namely _944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py. Please check this place to learn what is done there and why this might fail.
Please check if py2exe includes special treatment for pyautowin.
Just now I fixed this @korniichuk
Create folder comtypes/gen/ in the same folder of your test.py, and copy file _944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py and UIAutomationClient.py (under Lib/site-packages/comtypes/gen/) into this folder.
Then use pyinstaller --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient test.py
Good luck
@luziling many thanks!!
Note:
This is work for me
pyinstaller --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient test.py --onefile --clean
But this is not work for me
pyinstaller --onefile --clean --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient test.py
Different is --onefile and --clean argument place. Maybe, first place of argument --clean is remove required files.
I've got a an additional issue with pywinauto and pyinstaller:
Traceback (most recent call last):
File "main.py", line 19, in <module>
from pywinauto import ElementNotFoundError, win32defines, MatchError, ElementAmbiguousError, win32functions
File "c:\users\panni\appdata\local\temp\pip-build-thtnju\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pywinauto\__init__.py", line 72, in <module>
File "c:\users\panni\appdata\local\temp\pip-build-thtnju\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pywinauto\findwindows.py", line 42, in <module>
File "c:\users\panni\appdata\local\temp\pip-build-thtnju\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pywinauto\controls\__init__.py", line 36, in <module>
File "c:\users\panni\appdata\local\temp\pip-build-thtnju\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pywinauto\controls\uiawrapper.py", line 46, in <module>
File "c:\users\panni\appdata\local\temp\pip-build-thtnju\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pywinauto\uia_defines.py", line 181, in <module>
File "site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
File "site-packages\pywinauto\uia_defines.py", line 50, in __call__
File "site-packages\pywinauto\uia_defines.py", line 60, 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 704, in ComInterface
File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
File "site-packages\comtypes\tools\codegenerator.py", line 725, in ComInterfaceHead
File "site-packages\comtypes\tools\codegenerator.py", line 185, in generate
File "site-packages\comtypes\tools\codegenerator.py", line 631, 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
ImportError: No module named _00020430_0000_0000_C000_000000000046_0_2_0
[20380] Failed to execute script main
_00020430_0000_0000_C000_000000000046_0_2_0.py
included in comtypes\gen
and besides the main.py
.
Windows 10 Pro, newest update.
@luziling no need to create folders or copy files (however I only use the win32 backend)
pyinstaller --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient main.py --onefile
PyInstaller 3.3.1 Python 3.6.5 pywinauto 0.6.4
I've recently had an issue similar to this. After much trial-and-error, I fixed it by adding these to my pyinstaller command line:
--hidden-import comtypes
--hidden-import comtypes.gen
--hidden-import comtypes.patcher
--hidden-import comtypes.GUID
My application throwed a different error:
AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation'
It turned out that comtypes.gen
package is not present initially but generated only when requested. This caused error when building in a fresh virtual env. The solution is:
python -c "import pywinauto"
pyinstaller ... --hidden-import=comtypes.gen.UIAutomationClient ...
(python 3.6.8, pywinauto 0.6.6, comtypes 1.1.7, pyinstaller 3.4)
@luziling any possible drawbacks on this solution that you can foresee? My main concern would be freezing it on windows 10, but then it not working on another version of windows.
Hi , has anyone got this as the error:
import pywinauto.application
File "
@GoelPri Open a new issue and fill out the bug report template. That looks unreleated.
@GoelPri Open a new issue and fill out the bug report template. That looks unreleated.
Sure
Hi all,
need help with PyInstaller and Pywinauto lib.
test.py
file (one liner):Create EXE file based on
test.py
file:PyInstaller output:
Run created
test.exe
file. Output:So, error is:
test.spec
file:Environment: