py2exe 无法生成可执行文件
我在 XP 上使用 python 2.6。 我刚刚安装了 py2exe,我可以从 hello.py 成功创建一个简单的 hello.exe。 但是,当我尝试在实际程序中使用 py2exe 时,py2exe 会生成一些信息消息,但无法在 dist 文件夹中生成任何内容。
我的 setup.py 看起来像这样:
from distutils.core import setup
import py2exe
setup(console=['ServerManager.py'])
py2exe 输出看起来像这样:
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 感到有点惊讶,因为我没有明确导入它)。 另外,我的程序用这个命令启动得非常愉快:
python ServerManager.py
显然我正在做一些根本错误的事情,但在没有来自 py2exe 的任何错误消息的情况下,我不知道是什么。
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.
My setup.py looks like this:
from distutils.core import setup
import py2exe
setup(console=['ServerManager.py'])
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 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
Clearly I am doing something fundamentally wrong, but in the absence of any error messages from py2exe I have no idea what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我把它放在我所有的 setup.py 脚本中:
这使 py2exe 保持安静,但您仍然需要确保 dll 位于用户的计算机上。
I put this in all my setup.py scripts:
This keeps py2exe quiet, but you still need to make sure that dll is on the user's machine.
我发现如果我注释掉程序中使用 wxPython 的部分,py2exe 就可以正常工作。 另外,当我在下载附带的“简单”示例上使用 py2exe 时(即在 Python26\Lib\site-packages\py2exe\samples\simple 中),我收到此错误消息:
So some about wxPython made py2exe think I need Visual Studio 2008 DLL。 我没有 VS2008,但我的程序作为 Python 模块的目录运行得很好。 我在网上找到了 MSVCP90.DLL 的副本,将其安装在 Python26/DLL 中,并且 py2exe 现在可以正常工作。
我仍然不明白这种依赖关系从何而来,因为我可以在没有 py2exe 的情况下完美运行我的代码。 同样令人烦恼的是 py2exe 没有像 test_wx.py 示例那样给我错误消息。
进一步更新:当我尝试在另一台电脑上运行 py2exe 的输出时,我发现它需要安装 MSVCR90.DLL; 因此,如果您的目标 PC 尚未安装 Visual C++ 2008,我建议您下载并安装 Microsoft Visual C++ 2008 可再发行组件包。
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:
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.
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.
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.
wxPython 与此无关。 在 Python 2.6 之前,Python 使用 Visual Studio 2003 作为 Windows 编译器。 从 2.6 开始,他们切换到 Visual Studio 2008,这在某些情况下需要清单文件。 这已得到充分记录。 请参阅以下链接:
http://wiki.wxpython.org/py2exe
http://py2exe.org/index.cgi/Tutorial#Step52
另外,如果您要使用以下命令创建 wxPython 应用程序py2exe,那么你要设置 Windows 参数,而不是控制台参数。 也许我的教程会对您有所帮助:
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
wxPython has nothing to do with it. Before Python 2.6, Python used Visual Studio 2003 as their Windows compiler. Beginning with 2.6, they switched to Visual Studio 2008, which requires a manifest file in some situations. This has been well documented. See the following links:
http://wiki.wxpython.org/py2exe
http://py2exe.org/index.cgi/Tutorial#Step52
Also, if you're creating a wxPython application with py2exe, then you want to set the windows parameter, NOT the console one. Maybe my tutorial will help you:
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
看起来这只是 Python 2.6 的依赖项。 我在 2.5 下没有遇到此错误,但升级后我出现了。
此电子邮件主题提供了有关问题存在原因以及解决方法的一些背景知识:
http://www.nabble.com/py2exe, -Py26,-wxPython-and-dll-td20556399.html
我不想安装 vcredist。 我的应用程序当前不需要安装,并且可以由非管理员运行,这是我不想失去的行为。 因此,我按照链接中的建议进行操作,并通过“仅针对此用户”安装 Python 来获取必要的 Microsoft.VC90.CRT.manifest 和 msvcr90.dll。 我还需要在“所有用户”Python 2.6 安装的 WinSxS 文件夹中找到的 msvcp90.dll。 由于我已经拥有这三个中的两个,因此我包含了 msvcm90.dll 以防止将来出现错误,尽管当我忽略它时并没有立即收到任何错误。 我将清单和三个 DLL 放在我的冻结应用程序使用的 libs 文件夹中。
我必须执行的技巧是在 py2exe 生成的可执行文件旁边的应用程序文件夹的根目录中包含清单和 msvcr90.dll 的附加副本。 该 DLL 的副本用于引导应用程序,但它似乎只在 libs 文件夹中查找。
希望这个发现可以帮助其他人。
另外,我在让 py2exe 记录真实错误消息时遇到了同样的问题。 然后我意识到 stderr 没有被重定向到我的日志文件中。 在调用 py2exe 的命令行上添加“> build.log 2>&1”。
It looks like this is only a dependency for Python 2.6. I wasn't getting this error under 2.5, but after the upgrade I am.
This email thread has some background for why the problem exists and how to fix it:
http://www.nabble.com/py2exe,-Py26,-wxPython-and-dll-td20556399.html
I didn't want to have to install the vcredist. My application currently requires no installation and can be run by non-administrators, which is behavior I don't want to lose. So I followed the suggestions in the links and got the necessary Microsoft.VC90.CRT.manifest and msvcr90.dll by installing Python "for this user only". I also needed msvcp90.dll that I found in the WinSxS folder of an "all users" Python 2.6 install. Since I already had two of the three, I included msvcm90.dll to prevent future errors though I didn't get any immediate errors when I left it out. I put the manifest and the three DLLs in the libs folder used by my frozen application.
The trick I had to perform was including an additional copy of the manifest and msvcr90.dll in the root of my application folder next to by py2exe generated executable. This copy of the DLL is used to bootstrap the application, but then it appears to only look in the libs folder.
Hopefully that discovery helps someone else out.
Also, I had the same problem with having py2exe log a real error message. Then I realized that stderr wasn't getting redirected into my log file. Add "> build.log 2>&1" on the command line where you invoke py2exe.
在每个 Windows 上,您都可以在
C:\\WINDOWS\\WinSxS\\
的某个子目录中找到文件MSVCP90.dll
在我的例子中,该目录是:
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2
。转到
C:\\WINDOWS\\WinSxS\\
并使用 Windows 文件搜索查找MSVCP90.dll
。On each Windows, you can find the file
MSVCP90.dll
in some subdirectory inC:\\WINDOWS\\WinSxS\\
In my case, the directory was:
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2
.Go to
C:\\WINDOWS\\WinSxS\\
and use windows file search to findMSVCP90.dll
.仅供您参考,对我来说,复制文件
Microsoft.VC90.CRT.manifest 是有效的
msvcr90.dll
放入用户计算机(未安装 python 或 VC 可再发行组件)上带有 .exe 的目录中。
感谢这里的所有提示!
Just for your info, for me it worked to copy the files
Microsoft.VC90.CRT.manifest
msvcr90.dll
into the directory with the .exe on the user's machine (who has no python or VC redistributable installed).
Thanks for all the hints here!
输出表明您正在使用 WX。 尝试使用指定为 GUI 应用程序而不是控制台的脚本来运行 py2exe。 如果我没记错的话,这往往会导致 py2exe 出现问题。
The output says you're using WX. Try running py2exe with your script specified as a GUI app instead of console. If I'm not mistaken, that tends to cause problems with py2exe.
试试这个: http://www.py2exe.org/index.cgi/Tutorial#Step52< /a>
这对我有用
Try this: http://www.py2exe.org/index.cgi/Tutorial#Step52
It worked for me
wxPython wiki 上有一些信息。
部署 Python 应用
py2exe 与 wxPython 和 Python 2.6
There is some info on the wxPython wiki.
Deploy a Python app
py2exe with wxPython and Python 2.6
在我的win8.1上,我找不到路径
相反,该dll位于
XXX可能根据您的电脑而有所不同
您可以在路径中搜索,然后将路径添加到您的setup.py中
On my win8.1, I do not find the path
On the contrary , the dll is found in
The XXX may vary according to your PC
You may search in the path , then add the path in you setup.py