Overriding Criteria for Including DLLs

When py2exe comes across a DLL file that is required by the application, it decides whether or not includes the DLL file in the distribution directory using various criteria. Generally, it doesn't include DLLs if it thinks they belong to the "system" rather than the "application". There is a function that determines whether a specific DLL is a "system" DLL or not. DLLs found in directories like C:\WINNT\system32\MSVCP71.dll aren't included except for a special list of exceptions. If you'd like to override the decision for specific DLL files you can use the hack below in your setup.py file


# setup.py
from distutils.core import setup
import py2exe,sys,os

origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
        if os.path.basename(pathname).lower() in ("msvcp71.dll", "dwmapi.dll"):
                return 0
        return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL

[remainder of setup.py stuff]

In the example above, we've over-ridden the function py2exe.build_exe.isSystemDLL with our own copy that forces msvcp71.dll and dwmapi.dll to be considered "application" DLLs instead of "system" DLLs. This should cause py2exe to include them in the application distribution directory. For any other DLL it returns the previous default status as returned by the original isSystemDLL function.


If you use the above mechanism to trick py2exe into distributing any "system" DLLs, check to make sure that you're allowed to distribute those DLLs with your application or else Steve Ballmer [yadda, yadda, yadda] your cat.

OverridingCriteraForIncludingDlls (last edited 2008-07-08 11:27:43 by localhost)