Embedded Python does not find some modules, (ctypes, ...)
<p>I am trying to run some embedded python code.<br>
<strong>while some of it works fine</strong> some of the imports do no work.</p>

<pre><code>// pseudo code
...
Py_SetPath("//path//to//python35.zip");
...
Py_Initialize();
PyEval_InitThreads();

char * s = "import ctypes\n\nctypes.windll.user32.LockWorkStation()";
...
PyObject *main_module = PyImport_AddModule("__main__");
PyObject *main_dict = PyModule_GetDict(main_module);
...
PyObject * PyRes = PyRun_String(s, Py_file_input, main_dict, main_dict);
...
</code></pre>

<p>in fact, if all I do is call, </p>

<pre><code>...
char * s = "import ctypes";
...
</code></pre>

<p>I get an error, ("ctypes" is not found).</p>

<p>But if I do ...</p>

<pre><code>...
import time
t = time.ctime()
...
</code></pre>

<p>It works fine, so clearly some modules are loaded while others are not.</p>

<p>Any suggestions as to why "ctypes" would throw an error while others don't?</p>

<p><strong>Edit</strong> : more code...</p>

<pre><code>#include &lt;python.h&gt;

int main()
{
  ////////////////////////////////////////////////////////////////////////
  Py_SetPath( L"path\\to\\python35.zip" );
  Py_Initialize();
  PyEval_InitThreads();
  PyThreadState *mainstate = PyThreadState_Get();
  PyEval_ReleaseLock();

  //
  // ...
  //
  // run the code.
  PyEval_AcquireLock();
  PyInterpreterState* mainInterpreterState = mainstate-&gt;interp;

  PyObject *main_module = PyImport_AddModule("__main__");
  PyObject *main_dict = PyModule_GetDict(main_module);
  Py_INCREF(main_module);

  PyObject *local_dic = PyDict_New();
  Py_XINCREF(local_dic);

  // we can now run our script
  const char* s = "import ctypes";
  PyObject * PyRes = PyRun_String(s, Py_file_input, main_dict, local_dic);
  PyObject* ex = PyErr_Occurred();
  if (NULL != ex)
  {
    //  didn't work, import error.
  }
  PyErr_Clear();

  PyDict_Clear(local_dic);
  Py_XDECREF(local_dic);
  Py_DECREF(main_module);

  PyThreadState_Swap(NULL);
  PyThreadState_Swap(mainstate);
  PyEval_ReleaseLock();

  //
  // ...
  //

  // close
  PyEval_AcquireLock();
  PyThreadState_Swap(mainstate);
  Py_Finalize();
  //////////////////////////////////////////////////////////////////////////
}
</code></pre>