title: Python Embedding with IPython: WindowsError: [Error 193] %1 is not a valid Win32 application
body: <p>Trying to run:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  int
  main(int argc, char *argv[])
  {
    Py_SetProgramName(argv[0]);  /* optional but recommended */
    Py_Initialize();
    PyRun_SimpleString("import IPython\n"
                       "IPython.embed()\n");
    Py_Finalize();
    return 0;
  }
  </code></pre>
  
  <p>compiled with mignw64 gcc 4.6.0 ( <code>g++ -I /c/prog64/Python27/include t.cpp /c/prog64/Python27/libs/libpython27.a</code> ) under Windwos 7 I get the error:</p>
  
  <pre><code>$ a.exe
  Traceback (most recent call last):
    File "&lt;string&gt;", line 2, in &lt;module&gt;
    File "c:\prog64\python27\lib\site-packages\IPython\terminal\embed.py", line 290, in embed
      shell = InteractiveShellEmbed.instance(**kwargs)
    File "c:\prog64\python27\lib\site-packages\IPython\config\configurable.py", line 354, in instance
      inst = cls(*args, **kwargs)
    File "c:\prog64\python27\lib\site-packages\IPython\terminal\embed.py", line 92, in __init__
      display_banner=display_banner
    File "c:\prog64\python27\lib\site-packages\IPython\terminal\interactiveshell.py", line 328, in  __init__
      **kwargs
    File "c:\prog64\python27\lib\site-packages\IPython\core\interactiveshell.py", line 483, in __init__
      self.init_readline()
    File "c:\prog64\python27\lib\site-packages\IPython\core\interactiveshell.py", line 1817, in init_readline
      import IPython.utils.rlineimpl as readline
    File "c:\prog64\python27\lib\site-packages\IPython\utils\rlineimpl.py", line 21, in &lt;module&gt;
      _rl = __import__(_rlmod_name)
    File "c:\prog64\python27\lib\site-packages\readline.py", line 6, in &lt;module&gt;
      from pyreadline.rlmain import Readline
    File "c:\prog64\python27\lib\site-packages\pyreadline\__init__.py", line 11, in &lt;module&gt;
      from . import unicode_helper, logger, clipboard, lineeditor, modes, console
    File "c:\prog64\python27\lib\site-packages\pyreadline\console\__init__.py", line 15, in &lt;module&gt;
      from .console import *
    File "c:\prog64\python27\lib\site-packages\pyreadline\console\console.py", line 610, in &lt;module&gt;
      msvcrt = cdll.LoadLibrary(ctypes.util.find_msvcrt())
    File "C:\prog64\Python27\Lib\ctypes\__init__.py", line 443, in LoadLibrary
      return self._dlltype(name)
    File "C:\prog64\Python27\Lib\ctypes\__init__.py", line 365, in __init__
      self._handle = _dlopen(self._name, mode)
  WindowsError: [Error 193] %1 is not a valid Win32 applicationTraceback (most recent call last):
  </code></pre>
  
  <p>Note that other commands in the <code>PyRun_SimpleString</code> do work; also, in a command line python session:</p>
  
  <pre><code>import IPython
  IPython.embed()
  </code></pre>
  
  <p>works.</p>
  
  <p>I expect the problem is related to MSVCR90.DLL where the _dlopen looks for, and the fact that g++ links to the "normal" MSVCRT.DLL. Compiling with VS2008 is no easy option. Same error message is seen when compiling with VS2010. Python setup is Anaconda Python 2.7.8 64 bit.</p>