title: ImportError importing .pyd - DLL load failed. Cython
body: <p>I am trying to Cythonize this code (<code>GDTest.pyx</code>):</p>
  
  <pre><code>cimport numpy as np
  import numpy as np
  
  DTYPE = np.float64
  ctypedef np.float64_t DTYPE_t
  
  # Generates a matrix of Dirichlet random variates of size K
  # Argument alpha: J x K matrix of Dirichlet parameters
  # Returns g: J x K matrix of J Dirichlet draws, each of dimension K 
  # (each row sums to 1)
  def GenerateDirich(np.ndarray alpha):
      assert alpha.dtype==np.float64
      cdef double fuzz = pow(10,-200)
      cdef np.ndarray g=np.zeros((alpha.shape[0],alpha.shape[1]), dtype=DTYPE)
      cdef np.ndarray gSum
      g[:,:] = np.maximum(np.random.gamma(alpha[:,:]),fuzz)
      gSum = np.sum(g,axis=1)
      gSum = gSum[:,np.newaxis]
      g = np.copy(g/(np.kron(np.ones((1,alpha.shape[1])),gSum)))
      g=np.copy(g/np.repeat(gSum,alpha.shape[1]).reshape((gSum.shape[0],alpha.shape[1])))
  return g
  </code></pre>
  
  <p>Here is my <code>setup.py</code>:</p>
  
  <pre><code>from distutils.core import setup
  from Cython.Build import cythonize
  import numpy
  
  setup(
      ext_modules=cythonize('GDTest.pyx'),
      include_dirs=[numpy.get_include()]
  )
  </code></pre>
  
  <p>When I run the line:</p>
  
  <pre><code>python setup.py -c mingw64 --inplace
  </code></pre>
  
  <p>I get a bunch of warnings (deprecated numpy API, and a few related to <code>_Pyx_RaiseTooManyValuesError</code>) but then it creates <code>GDTest.pyd</code>.  When I try to import it, I get the error:</p>
  
  <pre><code>ImportError:DLL Load Failed: A dynamic link library (DLL) initialization routine failed.
  </code></pre>
  
  <p>I ran dependency walker and this is what it has listed as missing:</p>
  
  <pre><code>API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL
  
  API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL
  
  API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL
  
  MSVCR90.DLL
  
  API-MS-WIN-CORE-SHUTDOWN-L1-1-1.DLL
  
  EXT-MS-WIN-NTUSER-UICONTEXT-EXT-L1-1-0.DLL
  
  IESHIMS.DLL
  </code></pre>
  
  <p>The odd thing is that if I try to import it a second time (<code>import GDTest</code>) it works.  Any thoughts on how to fix this issue?</p>
  
  <p>Thanks!</p>