Here is my code:
from distutils.msvc9compiler import MSVCCompiler target_python_file = "main.py" ccode = """#include <Python.h> int main(int argc, char *argv[]) { PyObject* PyFileObject; putenv("PYTHONPATH=lib"); putenv("PYTHONHOME=."); Py_SetProgramName(argv[0]); Py_Initialize(); PyFileObject = PyFile_FromString("%s", "r"); PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), "%s", 1); Py_Finalize(); return 0; } """ % (target_python_file, target_python_file) with open("main.c","w") as main: main.write(ccode) compiler = MSVCCompiler() compiler.compile(["main.c"],include_dirs=["C:/Python27/include"]) compiler.link("",["main.obj"],"python_launcher.exe",libraries=["python27"], library_dirs=["C:/Python27/libs"])
When I run this, python_launcher.exe appears, however, when I try to start it, I get an invalid win32 application error.
I can compile the same code using visul C ++ 2008 and it works, but I want to use distutils for this because I want it to define configuration options for the compiler.
Debug
I tried to open the created executable in WinDebug, but I could not open it because it happened: 
The Turkish side claims that this is not a valid Win32 application.
source share