Search code examples
pythonpy2exepywinauto

ImportError: No module named allcontrols with pywinauto and py2exe


I want to generate an .exe file from a python script which includes the pywinauto module.

It builds fine, however when running the resulting dist\pywinauto_sample.exe, I get this error:

Traceback (most recent call last):
  File "pywinauto_sample.py", line 2, in <module>
    from pywinauto import application
  File "pywinauto\application.pyc", line 68, in <module>
  File "pywinauto\controlactions.pyc", line 45, in <module>
  File "pywinauto\tests\__init__.pyc", line 128, in <module>
  File "pywinauto\tests\__init__.pyc", line 114, in __init_tests
ImportError: No module named allcontrols

Here's my pywinauto_sample.py:

import pywinauto
from pywinauto import application
app = pywinauto.application.Application()

And here's my setup.py:

from distutils.core import setup
import py2exe

setup(console=['pywinauto_sample.py'])

I compile the program with:

python setup.py py2exe

Solution

  • Add this to your setup.py:

    from distutils.core import setup
    import py2exe
    
    setup(
        console=
        [
            'pywinauto_sample.py'
        ],
        options=
        {
            "py2exe":
            {
                "includes":
                [
                    "pywinauto.tests.truncation",
                    "pywinauto.tests.translation",
                    "pywinauto.tests.repeatedhotkey",
                    "pywinauto.tests.overlapping",
                    "pywinauto.tests.missingextrastring",
                    "pywinauto.tests.missalignment",
                    "pywinauto.tests.miscvalues",
                    "pywinauto.tests.leadtrailspaces",
                    "pywinauto.tests.comparetoreffont",
                    "pywinauto.tests.comboboxdroppedheight",
                    "pywinauto.tests.asianhotkey",
                    "pywinauto.tests.allcontrols",
                ]
            }
        }
    )
    

    Source: http://permalink.gmane.org/gmane.comp.python.py2exe/4663