py2exe gotcha: Building on Windows Vista/7, deploying to XP

py2exe is a fantastic module that will package up a Python program into an executable that will run on Windows.

py2exe is amazingly good at sussing out your program's dependencies, but it's a complex task, and inevitably there are some gotchas.

One of them is the DLL file "POWRPROF.DLL".

This happens when building your executable on Windows Vista/7, and then deploying it on Windows XP. Since this has bitten me twice now, I thought I'd describe it here.

Windows Vista starting shipping a version of POWRPROF.DLL that is incompatible with XP and earlier. Because of the rules that XP uses for DLL lookup, if py2exe includes this DLL, then it won't find the correct one in your system directory.

Typically, the error you'll get when running your compiled program on Windows 2000/XP is "ImportError: DLL load failed: The specified procedure could not be found.", raised by win32api.

The fix is to add "POWRPROF.DLL" to the list of "dll_excludes" passed into py2exe. That will make your executable use whichever version is in the Windows system directory (and will save you a few KB on your bundled app size).

Here's how I do this with the setup script of one of my programs, Align Assist:

    options = dict(optimize=2,
               dist_dir=app_name,
               excludes=excludes,
               packages=packages,
               dll_excludes=["POWRPROF.dll"])

    setup_dict['options'] = {"py2exe" : options}

1 comment to py2exe gotcha: Building on Windows Vista/7, deploying to XP

  • Fabian Silva

    thanks, I’m newbie in the python world and when I see that deleting this dll worked, I found your post that say why 🙂

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>