title: Py_Initialize fails - unable to load the file system codec
body: <p>I am attempting to put together a simple c++ test project that uses an embedded python 3.2 interpreter. The project builds fine but Py_Initialize raises a fatal error:</p>
  
  <pre><code>Fatal Python error: Py_Initialize: unable to load the file system codec
  LookupError: no codec search functions registered: can't find encoding
  </code></pre>
  
  <p><strong>Minimal code:</strong></p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  int main (int, char**)
  {
    Py_Initialize ();
    Py_Finalize ();
    return 0;
  }
  </code></pre>
  
  <p>The OS is 32bit Vista.</p>
  
  <p>The python version used is a python 3.2 debug build, built from sources using VC++ 10.</p>
  
  <p>The python_d.exe file from the same build runs without any problems.</p>
  
  <p>Could someone explain the problem and how to fix it? My own google-fu fails me.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>After going through the python source code I've found that, as the error says, no codec search functions have been registered. Both <code>codec_register</code> and <code>PyCodec_Register</code> are as they should be. It's just that nowhere in the code are any of these functions called.</p>
  
  <p>I don't really know what this means as I still have no idea when and from where these functions should have been called. The code that raises the error is entirely missing from the source of my other python build (3.1.3).</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Answered my own question below.</p>