Windows Server 无法执行 py2exe 生成的应用程序
一个简单的Python脚本需要在没有安装Python的Windows服务器上运行。
我使用 py2exe,它生成了一个健康的 dist 子目录,其中 script.exe 在本地计算机上运行良好。
但是,当我在服务器(Windows Server 2003 R2)上运行它时,它会生成以下内容:
系统无法执行指定的程序。
并且 ERRORLEVEL 为 9020。
有什么想法吗?
A simple python script needs to run on a windows server with no python installed.
I used py2exe, which generated a healthy dist subdirectory, with script.exe that runs fine on the local machine.
However, when I run it on the server (Windows Server 2003 R2), it produces this:
The system cannot execute the specified program.
and ERRORLEVEL is 9020.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了使 py2exe 工作,您必须在应用程序中包含正确版本的 Microsoft C 运行时 DLL。
对于 Python2.6,这是 MSVCR90.dll 版本 9.0.21022.8,可以从 Microsoft Visual C++ 2008 Redistributable Package 获取:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf& displaylang=en
请注意,此安装程序的 SP1 包含不同版本的 DLL,因此无法运行。
今年早些时候我花了一段时间在 py2exe 教程中仔细解释了这一点,所以我将链接到该内容:
http://www.py2exe.org/index.cgi/Tutorial#Step5
For py2exe to work, you have to include the correct version of the Microsoft C runtime DLL with your application.
For Python2.6, this is MSVCR90.dll version 9.0.21022.8, which can be obtained from the Microsoft Visual C++ 2008 Redistributable Package:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
NOTE that the SP1 of this installer contains a different version of the DLL, and will not work.
I spent a while earlier this year explaining this carefully in the py2exe tutorial, so I'll just link to that:
http://www.py2exe.org/index.cgi/Tutorial#Step5
它可能缺少一些必需的 DLL。尝试使用 depends.exe 来确定可能缺少的内容。它可能是一个 msvc-something-something.dll
It could be missing some required DLLs. Try using depends.exe to identify what might be missing. It's probably an msvc-something-something.dll
我没有找到问题的原因,但在同一脚本上使用 python 2.5 和 py2exe 在服务器上运行良好。
我猜2.6下的py2exe有问题。
I did not find the cause to the problem, but using python 2.5 with py2exe on the same script worked fine on the server.
I guess there is something wrong with py2exe under 2.6.
由于 Python 2.6 是针对 Visual Studio 2008 构建的,因此目标计算机还必须具有 Visual Studio 2008 库(可从 Visual C++ 2008 可再发行组件包。
我确认,在 Windows XP 或 Server 2003 的全新版本(两者都没有 Visual Studio 2008 可再发行组件)上,Python 2.6 py2exe 可执行文件将因上述错误而失败,但在安装可再发行组件包后,可执行文件可以正常运行。
Because Python 2.6 is built against Visual Studio 2008, the target machine must also have the Visual Studio 2008 libraries, available from the Visual C++ 2008 Redistributable package.
I confirmed that on a clean build of Windows XP or Server 2003 (neither of which have the Visual Studio 2008 redistributable), a Python 2.6 py2exe executable will fail with the aforementioned error, but after installing the redistributable package, the executable runs normally.