Differences between revisions 4 and 5
Revision 4 as of 2008-07-08 11:27:43
Size: 1993
Editor: localhost
Comment: converted to 1.6 markup
Revision 5 as of 2015-01-22 12:31:06
Size: 2096
Editor: qqii
Comment: py2exe.build_exe no longer exists
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
import py2exe,sys,os import py2exe
Line 28: Line 28:
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
old_determine_dll_type = py2exe.dllfinder.DllFinder.determine_dll_type
pack = ["msvcp71.dll", "dwmapi.dll"]
def determine_dll_type(self, imagename):
    for p in pack:
        if imagename.endswith(p):
            return "EXT"
    return old_determine_dll_type(self, imagename)
py2exe.dllfinder.DllFinder.determine_dll_type = determine_dll_type
Line 39: Line 41:
py2exe.build_exe.isSystemDLL with our own copy that forces py2exe.dllfinder.DllFinder.determine_dll_type with our own copy that forces
Line 43: Line 45:
previous default status as returned by the original isSystemDLL function. previous default status as returned by the original determine_dll_type function.

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

Example

# setup.py
from distutils.core import setup
import py2exe

old_determine_dll_type = py2exe.dllfinder.DllFinder.determine_dll_type
pack = ["msvcp71.dll", "dwmapi.dll"]
def determine_dll_type(self, imagename):
    for p in pack:
        if imagename.endswith(p):
            return "EXT"  
    return old_determine_dll_type(self, imagename)
py2exe.dllfinder.DllFinder.determine_dll_type = determine_dll_type

[remainder of setup.py stuff]

In the example above, we've over-ridden the function py2exe.dllfinder.DllFinder.determine_dll_type 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 determine_dll_type function.

Disclaimer

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 2015-01-22 12:39:07 by qqii)