views:

468

answers:

4

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?

+2  A: 

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

Ned Batchelder
That was my initial guess, but unfortunately all dlls are in place.
Paul Oyster
A: 

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.

Paul Oyster
Py2exe works fine on Python2.6, I have used it many times. You must be careful which version of the microsoft visual C runtime DLL you include with your distributed application. The details are explained in step 5 of the py2exe tutorial:http://www.py2exe.org/index.cgi/Tutorial#Step5
Tartley
+1  A: 

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.

Jason R. Coombs
Hey. I'm pretty sure that the Visual C++ 2008 redistributable package *SP1* you linked to is the wrong version. The SP1 has the wrong version C runtime DLL in it, and will not work. See my answer below for the right version.
Tartley
Interesting. I thought I had tested it with the SP1 redistributable, but apparently I was mistaken. Thanks for the correction.
Jason R. Coombs
+2  A: 

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.

This is all explained in the py2exe tutorial:

http://www.py2exe.org/index.cgi/Tutorial#Step5

Tartley