py2exe 无法生成可执行文件 [英] py2exe fails to generate an executable
问题描述
我在 XP 上使用 python 2.6.我刚刚安装了py2exe,我可以从hello.py成功创建一个简单的hello.exe.但是,当我尝试在我的真实程序上使用 py2exe 时,py2exe 会生成一些信息消息,但无法在 dist 文件夹中生成任何内容.
I am using python 2.6 on XP. I have just installed py2exe, and I can successfully create a simple hello.exe from a hello.py. However, when I try using py2exe on my real program, py2exe produces a few information messages but fails to generate anything in the dist folder.
我的 setup.py 看起来像这样:
My setup.py looks like this:
from distutils.core import setup
import py2exe
setup(console=['ServerManager.py'])
py2exe 输出如下所示:
and the py2exe output looks like this:
python setup.py py2exe
running py2exe
creating C:\DevSource\Scripts\ServerManager\build
creating C:\DevSource\Scripts\ServerManager\build\bdist.win32
...
...
creating C:\DevSource\Scripts\ServerManager\dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'wx._misc_' (C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> wx._misc_.pyd)
creating python loader for extension 'lxml.etree' (C:\Python26\lib\site-packages\lxml\etree.pyd -> lxml.etree.pyd)
...
...
creating python loader for extension 'bz2' (C:\Python26\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
py2exe 似乎找到了我所有的导入(尽管我对提到 win32 感到有点惊讶,因为我没有明确导入它).另外,我的程序用这个命令启动得非常愉快:
py2exe seems to have found all my imports (though I was a bit surprised to see win32 mentioned, as I am not explicitly importing it). Also, my program starts up quite happily with this command:
python ServerManager.py
很明显我在做一些根本性的错误,但是在没有来自 py2exe 的任何错误消息的情况下,我不知道是什么.
Clearly I am doing something fundamentally wrong, but in the absence of any error messages from py2exe I have no idea what.
推荐答案
我发现如果我将程序中使用 wxPython 的部分注释掉,py2exe 就可以正常工作.此外,当我在下载附带的简单"示例上使用 py2exe 时(即在 Python26\Lib\site-packages\py2exe\samples\simple 中),我收到以下错误消息:
I've discovered that py2exe works just fine if I comment out the part of my program that uses wxPython. Also, when I use py2exe on the 'simple' sample that comes with its download (i.e. in Python26\Lib\site-packages\py2exe\samples\simple), I get this error message:
*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory
关于 wxPython 的一些事情让 py2exe 认为我需要一个 Visual Studio 2008 DLL.我没有 VS2008,但我的程序作为 Python 模块的目录运行得非常好.我在网上找到了一份 MSVCP90.DLL 的副本,将它安装在 Python26/DLLs 中,现在 py2exe 工作正常.
So something about wxPython makes py2exe think I need a Visual Studio 2008 DLL. I don't have VS2008, and yet my program works perfectly well as a directory of Python modules. I found a copy of MSVCP90.DLL on the web, installed it in Python26/DLLs, and py2exe now works fine.
我仍然不明白这种依赖是从哪里来的,因为我可以在没有 py2exe 的情况下完美地运行我的代码.py2exe 没有像 test_wx.py 示例那样给我一条错误消息,这也很烦人.
I still don't understand where this dependency has come from, since I can run my code perfectly okay without py2exe. It's also annoying that py2exe didn't give me an error message like it did with the test_wx.py sample.
进一步更新:当我尝试在另一台 PC 上运行 py2exe 的输出时,我发现它需要安装 MSVCR90.DLL;因此,如果您的目标 PC 尚未安装 Visual C++ 2008,我建议您下载并安装 Microsoft Visual C++ 2008 可再发行包.
Further update: When I tried to run the output from py2exe on another PC, I discovered that it needed to have MSVCR90.DLL installed; so if your target PC hasn't got Visual C++ 2008 already installed, I recommend you download and install the Microsoft Visual C++ 2008 Redistributable Package.
这篇关于py2exe 无法生成可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!