py2exe(0.6.9)已经很过时了,如果不做一些额外的修改,就不能很好地处理较新的Windows版本。特别是,默认情况下,它将包含一些不应该绑定的Windows系统dll。要防止出现这种情况,请尝试按如下方式更改安装脚本:from distutils.core import setup
import py2exe
# Exclude system DLLs
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if os.path.basename(pathname).lower() in ("gdiplus.dll",
"mfc90.dll"):
return 0
if os.path.basename(pathname).lower() in ("powrprof.dll", ) or \
os.path.basename(pathname).lower().startswith("api-ms-win-"):
return 1
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
# Add the MS VC9 CRT and common controls manifest as resource to the exe
manifest = '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
version="0.0.0.0"
processorArchitecture="x86"
name="Enter program name here"
type="win32"
/>
Enter program description here
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b"
/>
'''
setup(script_args=['py2exe'],
windows=[{'script': 'progressdlgprobblem.py',
'other_resources': [(24, 1, manifest)]}],
options = {'py2exe': {'compressed': 1,
'dll_excludes': ['iertutil.dll',
'MPR.dll',
'msvcm90.dll',
'msvcp90.dll',
'msvcr90.dll',
'mswsock.dll',
'urlmon.dll',
'w9xpopen.exe'],
'bundle_files': 1}},
zipfile=None)
为了获得最佳的互操作性,您还需要复制微软.VC90.CRT.舱单,msvcm90.dll、msvcp90.dll和msvcr90.dll(来自C:\Windows\winsxs\x86)_微软.vc90.crt_1fc8b3b9ae118e3b_9.0.21022.8_none_bcb86ed6ac711f91(目录名可能略有不同,但是正确的版本9.0.21022.8是很重要的)到你的exe目录,这样用户就不需要自己安装正确版本的MS VC9 CRT。在
除此之外,您还可以尝试PyInstaller,它可以自动处理程序集依赖项,并在默认情况下排除系统dll。在