Skip to content Skip to sidebar Skip to footer

Python Embedding With IPython: WindowsError: [Error 193] %1 Is Not A Valid Win32 Application

Trying to run: #include int main(int argc, char *argv[]) { Py_SetProgramName(argv[0]); /* optional but recommended */ Py_Initialize(); PyRun_SimpleString('

Solution 1:

Problem indeed is related to msvcr90.dll. Way to solve it is to link the program against msvcr90.dll. However, to link against msvcr90.dll you need to have a manifest or you will get a runtime error. This manifest looks like:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

which I extracted from python.exe with a text editor and named msvcr90.manifest. This manifest is linked into the application using the resource file msvcr90.rc

#include "winuser.h"
1 RT_MANIFEST msvcr90.manifest

which in turned can be compiled into an object file using:

windres msvcr90.rc msvcr90.o

Than, compilation of the program with this resource file and msvcr90.dll becomes:

g++ -I /c/prog64/Python27/include t.cpp /c/prog64/Python27/libs/libpython27.a msvcr90.o msvcr90.dll

where I copied msvcr90.dll from c:/Windows/winsxs/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b/msvcr90.dll

Input for this came from

and a couple of other web pages which explained me how to do this.


Post a Comment for "Python Embedding With IPython: WindowsError: [Error 193] %1 Is Not A Valid Win32 Application"