I’ve been trying to pack my app with py2exe. The application works fine but it keeps failing to find/use pywinauto. I been googling but I get nothing, I’m now I’m totally lost…
Here’s the packing script:
from distutils.core import setup
setup(
windows = ["mainForm.py"],
data_files=[
('', ['mainForm.ui']),
('', ['osk.sqlite'])
],
options = {
"py2exe":{
"optimize": 2,
"includes": [
'sip', 'pyttsx.drivers.sapi5', 'win32com', 'xml.etree.ElementTree', 'sqlite3',
'pywinauto', 'pywinauto.application', 'pywinauto.controls', 'pywinauto.tests', 'SendKeys'
],
"typelibs": [('{C866CA3A-32F7-11D2-9602-00C04F8EE628}', 0, 5, 0)]
}
}
)
And here’s the ouput when running the exe
Traceback (most recent call last): File "mainForm.py", line 129, in changeState File "mainForm.py", line 230, in setWriteMode File "mainForm.py", line 105, in FillApps File "WindowHandler.pyo", line 26, in getWindowList NameError: global name 'pywinauto' is not defined
I hope anyone could point me into the right direct.
Thanks in advance
From my experience, py2exe handles imports in a weird way. Sometimes it has trouble finding linked-imports (like you import
WindowHandler, which importspywinauto).I would start with this in mainForm.py:
And in setup.py, start with this:
Make sure your program works before compiling to an exe, then try running setup.py.
When you start getting errors when running
setup.py(like the one you posted), add more imports to mainForm.py. So for that error, your new header will look like:It will not break your code because it will just be an “unused” import.
Keep doing that until setup.py works.