The Problem

A python program containing :

   1 import win32ui

generates an error in .exe mode (i.e. after being compiled with py2exe) :

Traceback (most recent call last):
  File "test_win32ui.py", line 5, in <module>
    import win32ui
  File "win32ui.pyo", line 12, in <module>
  File "win32ui.pyo", line 10, in __load
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

Explanation

win32ui needs the MFC (Microsoft Foundation Classes) DLLs to run in .exe mode.

Solution

Ship the needed DLLs with the application

The DLLs and a manifest file can be found in : "C:\Python26\Lib\site-packages\pythonwin\"

You will need the following files :

To copy files at compile time, add or modify the data_files option in your setup.py :

   1 mfcfiles = [os.path.join(mfcdir, i) for i in ["mfc90.dll", "mfc90u.dll", "mfcm90.dll", "mfcm90u.dll", "Microsoft.VC90.MFC.manifest"]]
   2 
   3 data_files = [("Microsoft.VC90.MFC", mfcfiles),
   4               ]
   5 
   6 setup(
   7     data_files = data_files,
   8     ...
   9   )

With this in place, running py2exe should put the files into your dist directory:

  dist
  |
  +-Microsoft.VC90.MFC
  | |
  | +-Microsoft.VC90.MFC.manifest
  | +-mfc90.dll
  | +-...
  |-...

Install "vcredist"

An alternative solution is to install the "Microsoft Visual C++ 2008 Redistributable Package". See Tutorial#Step522

Py2exeAndWin32ui (last edited 2011-03-28 16:07:17 by JimmyRetzlaff)