py2exe如何减少dll依赖?

2024-06-26 01:35:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我的程序依赖于USER32.dll、SHELL32.dll、ADVAPI32.dll WS2_32.dll、GDI32.dll和KERNEL32.dll。它们都在system32文件夹中。有没有办法可以把这些包括在我的程序中,这样它就可以在所有的Windows计算机上运行了?或者这些DLL是否已经在所有Windows安装中找到?在


Tags: 程序文件夹windows计算机dll办法system32user32
2条回答

我不确定py2exe,但cx_Freeze是一个类似的工具,正在积极更新。您可能需要使用bin-includes选项来列出依赖项,但默认情况下,它会创建一个包含依赖项的.exe文件。在

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

您需要重写py2exe根据哪些条件选择它包含在结果包中的DLL。下面将演示如何执行此操作

# 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

这段代码和上面的引文来自py2exe网站上的a page。请务必阅读该页,包括免责声明。在

相关问题 更多 >