exe generated with py2exe can't find pywinauto
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 imports pywinauto
).
I would start with this in mainForm.py:
import sys
import WordOps
import Voice
import WindowHandler
from PyQt import QtCore, QtGui, uic
And in setup.py, start with this:
options={'py2exe':{
'includes': ['sip'],
'bundle_files': 1
}
}
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:
import sys
import WordOps
import Voice
import WindowHandler
from PyQt import QtCore, QtGui, uic
# imports for py2exe
import pywinauto
It will not break your code because it will just be an "unused" import. Keep doing that until setup.py works.
精彩评论