CamelCaseGuy
CamelCaseGuy

Reputation: 291

py2exe - How do I reduce dll dependencies?

My program depends on USER32.dll, SHELL32.dll, ADVAPI32.dll WS2_32.dll, GDI32.dll, and KERNEL32.dll. All are in the system32 folder. Is there any way I can include these in my program so it will run on all Windows computers? Or are these dlls that can already be found on all installations of Windows?

Upvotes: 4

Views: 1680

Answers (2)

Boris Gorelik
Boris Gorelik

Reputation: 31767

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".

You need to override the criteria according to which py2exe selects the DLL's that it includes in the resulting package. The following shows how to do this

# 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

This code and the citation above were taken from a page on the py2exe site. Make sure you read that page, including the disclaimers.

Upvotes: 3

Velociraptors
Velociraptors

Reputation: 2030

I'm not sure about py2exe, but cx_Freeze is a similar utility that's actively updated. You may need to use the bin-includes option to list your dependencies, but by default it creates a single .exe file that includes the dependencies.

Upvotes: 2

Related Questions