如何调试 py2exe“应用程序无法正确初始化"错误? [英] How do I debug a py2exe 'application failed to initialize properly' error?

查看:46
本文介绍了如何调试 py2exe“应用程序无法正确初始化"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总的来说,我对 Python 非常陌生,但我在 Python 2.6/wxPython 2.8 中制作了一个应用程序,当我通过 Python 运行它时,它可以完美运行.但我想更进一步,能够将它部署为 Windows 可执行文件,所以我一直在尝试 py2exe.但我一直无法让它发挥作用.它总是会编译一个 exe,但是当我真正尝试运行它时,它会发出一些神秘的错误消息.起初,它们是简单的消息,说它找不到某些 DLL,但即使在给它所有想要的 DLL 之后,它现在也返回:

I'm very new to Python in general, but I made an app in Python 2.6 / wxPython 2.8 that works perfectly when I run it through Python. But I wanted to go a step further and be able to deploy it as a Windows executable, so I've been trying out py2exe. But I haven't been able to get it to work. It would always compile an exe, but when I actually try to run that it barks some cryptic error message. At first they were simple messages saying it couldn't find certain DLLs, but even after giving it all the DLLs it wanted, it now returns this:

The application failed to initialize properly (0xc0000142).
Click OK to terminate the application.

所以我把事情分解了,只是使用 wxPython 制作了一个非常非常简单的应用程序,只是为了看看它是否可行,或者我的原始应用程序的一些更复杂的功能是否受到阻碍.但即使是我的简单测试也返回了相同的错误.这是简单测试脚本的代码:

So I broke things down and just made a very, very simple application utilizing wxPython just to see if that would work, or if some of the more complicated features of my original app were getting in the way. But even my simple test returned the same error. Here's the code for the simple test script:

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 安装脚本:

And here's the py2exe setup script I used:

#!/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 时,我立即收到了上面引用的错误.

Then I run python setup.py py2exe, it generates the EXE file, warns about some DLL files (which I subsequently copy into the dist directory), but then when I try to run the EXE, I get the error I quoted above immediately.

推荐答案

请注意,有更高版本的 Visual C++ 2008 Redistributable 包:SP1.但是,SP1 和早期版本都不会将 DLL 安装到路径中.正如下载页面所说(我的重点):

Note that there is a later version of the Visual C++ 2008 Redistributable package: SP1. However, both the SP1 and the earlier release don't install the DLLs into the path. As the download page says (my emphasis):

这个包安装运行时C 运行时 (CRT) 的组件,标准 C++、ATL、MFC、OpenMP 和MSDIA 库.对于图书馆支持并行部署模型(CRT、SCL、ATL、MFC、OpenMP)它们是安装到本地程序集缓存,也称为 WinSxS 文件夹,位于Windows 操作系统的版本支持并行程序集.

This package installs runtime components of C Runtime (CRT), Standard C++, ATL, MFC, OpenMP and MSDIA libraries. For libraries that support side-by-side deployment model (CRT, SCL, ATL, MFC, OpenMP) they are installed into the native assembly cache, also called WinSxS folder, on versions of Windows operating system that support side-by-side assemblies.

您可能会在 %WINDIR%\WinSxS 文件夹中找到这些文件,而不是在路径中.我认为您需要做的是合并相关 DLL 的清单信息(在 %WINDIR%\WinSxS\Manifests) 到您的 setup.py.一世添加了以下部分:

You will probably find these files in the %WINDIR%\WinSxS folder and not in the path.What I think you need to do is incorporate the manifest information for the relevant DLLs (found in %WINDIR%\WinSxS\Manifests) into your setup.py. I added the following section:

<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.VC90.CRT"
            version="9.0.30729.4918"
            processorArchitecture="X86"
            publicKeyToken="1fc8b3b9a1e18e3b"
            language="*"
        />
    </dependentAssembly>
</dependency>

紧接在现有的 部分之后,并重建 exe:它运行没有问题.注意:根据您安装的 Visual C++ 文件的确切版本,上述信息可能不完全正确.查看系统上的清单并使用正确的versionpublicKeyToken

immediately after the existing <dependency> section, and rebuilt the exe: it ran without problems. Note: depending on exactly what version of the Visual C++ files you installed, the above info may not be exactly correct. Look at the manifests on your system and use the correct version, publicKeyToken etc.

或者,看看这个答案 了解如何使用您的应用程序部署 DLL(而不是假设它们已经存在于目标系统上).哦......我看到你问了那个原始问题;-)

Alternatively, look at this answer for how to deploy the DLLs with your application (as opposed to assuming they already exist on the target system). Oh ... I see you asked that original question ;-)

这篇关于如何调试 py2exe“应用程序无法正确初始化"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆