title: Trouble with modules while embedding python in C++
body: <p>I'm making a .dll for an .exe program and embedding python in it. It worked fine with this simple .py program</p>
  
  <pre><code>from time import *
  ##import OptimRestriction
  
  def test_callsign(b):
      ...(simple script)
      return 
  </code></pre>
  
  <p>What I did was copy the .py program, the Dll and Lib folders into the xxx.exe folder, like is said <a href="https://stackoverflow.com/questions/1387906/c-with-python-embedding-crash-if-python-not-installed">here</a>.</p>
  
  <p>But as soon as I uncomment the import of <code>OptimRestriction</code> the debug crashes.  First it starts loading symbols when the call to the thread that initializes and deals with Python is called: <code>_ctypes.pyd</code>,<code>_sockets.pyd</code>,<code>sst_pyd</code>,<code>harshlib.pyd</code>,<code>unicodedata.pyd</code>,<code>tkinter.pyd</code>, all modules that the <code>OptimRestriction</code> does not use.</p>
  
  <p>The error given after the debug crashes is:</p>
  
  <p><code>Unhandled exception at 0x1E0AA0C5 (python27.dll) in xxx.exe: 0xC0000005: Access violation reading location 0x00000004.</code></p>
  
  <p>And it breaks on the <code>_callthreadstart</code> function.</p>
  
  <p><code>OptimRestriction</code> is a long program that imports a lot of modules (that are also in the .exe folder). Here's the list of its imports:</p>
  
  <pre><code>from GrafFunc import *
  from LogFunc import *
  from DinamicaFunc import *
  from Dinamica2 import *
  from CDR import *
  ...
  import sys
  import cProfile"
  </code></pre>
  
  <p>What it seems to me is that the thread takes too long to start because the debug starts loading those files for a long time, and so it gives an error. Am I correct? And if so, why is it loading those files if <code>OptimRestriction</code>and its impots don't use them?</p>
  
  <p>Edit:New information. It crashes saying <code>Can't import module</code> on this line: 
  <code>pModule = PyImport_Import(pName);</code></p>