Windows Server cannot execute a py2exe-generated app
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?
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
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
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.
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.
精彩评论