一般来说,我对 Python 很陌生,但我在 Python 2.6 / wxPython 2.8 中制作了一个应用程序,当我通过 Python 运行它时,它可以完美运行。但我想更进一步,能够将其部署为 Windows 可执行文件,因此我一直在尝试 py2exe。但我无法让它工作。它总是会编译一个 exe,但是当我真正尝试运行它时,它会发出一些神秘的错误消息。起初它们只是简单的消息,说它找不到某些 DLL,但即使在给它所需的所有 DLL 之后,它现在也会返回:
The application failed to initialize properly (0xc0000142).
Click OK to terminate the application.
所以我打破了一切,只是使用 wxPython 制作了一个非常非常简单的应用程序,只是为了看看它是否可以工作,或者我的原始应用程序的一些更复杂的功能是否妨碍了我。但即使是我的简单测试也返回了同样的错误。这是简单测试脚本的代码:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, style=wx.DEFAULT_FRAME_STYLE ^ wx.MAXIMIZE_BOX)
panel = wx.Panel(self, -1, style = wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.FULL_REPAINT_ON_RESIZE)
main_sizer = wx.BoxSizer(wx.VERTICAL)
testtxt = wx.StaticText(panel, -1, label='This is a test!')
main_sizer.Add(testtxt, 0, wx.ALIGN_CENTER)
panel.SetSizerAndFit(main_sizer)
self.Show(1)
return
app = wx.PySimpleApp()
frame = MainWindow(None, -1, 'Test App')
app.MainLoop()
这是我使用的 py2exe 设置脚本:
#!/usr/bin/python
from distutils.core import setup
import py2exe
manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
version="0.64.1.0"
processorArchitecture="x86"
name="Controls"
type="win32"
/>
<description>Test Program</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
"""
setup(
windows = [
{
"script": "testme.py",
"icon_resources": [(1, "testme.ico")],
"other_resources": [(24,1, manifest)]
}
],
data_files=["testme.ico"]
)
然后我运行python setup.py py2exe
,它生成 EXE 文件,警告一些 DLL 文件(我随后将其复制到 dist 目录中),但是当我尝试运行 EXE 时,我立即收到上面引用的错误。