Py2exe使用教程(三)——Py2exe和Win32ui

本文译自Py2exe官网 http://www.py2exe.org/index.cgi/Py2exeAndWin32ui


问题

一个包含以下语句的 python 程序:

import win32ui

在exe 模式下产生一个错误 (也就是说,在使用 py2exe 完成编译后):

Traceback (most recent call last):
  File "test_win32ui.py", line 5, in <module>
    import win32ui
  File "win32ui.pyo", line 12, in <module>
  File "win32ui.pyo", line 10, in __load
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

解释

win32ui 需要 MFC (Microsoft Foundation Classes) DLLs 才能运行 .exe 模式。

解决方案

装载程序所需要的 DLL 库文件

这些 DLL库文件和一份清单文件可以在以下目录找到: "C:\Python26\Lib\site-packages\pythonwin\"

你将会需要以下几个文件:

  • mfc90.dll
  • mfc90u.dll
  • mfcm90.dll
  • mfcm90u.dll
  • Microsoft.VC90.MFC.manifest

为了能在编译时复制这些文件,在你的 setup.py 文件中添加或者修改 data_files 选项:

mfcfiles = [os.path.join(mfcdir, i) for i in ["mfc90.dll", "mfc90u.dll", "mfcm90.dll", "mfcm90u.dll", "Microsoft.VC90.MFC.manifest"]]

data_files = [("Microsoft.VC90.MFC", mfcfiles),
              ]

setup(
    data_files = data_files,
    ...
  )

在这种条件下,运行 py2exe 将会把这些文件放入你的 dist 目录:

  dist
  |
  +-Microsoft.VC90.MFC
  | |
  | +-Microsoft.VC90.MFC.manifest
  | +-mfc90.dll
  | +-...
  |-...

安装"vcredist"

另外一个解决方案是安装 "Microsoft Visual C++ 2008 Redistributable Package". 参照 Tutorial#Step522

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值