hashimba
hashimba

Reputation: 63

ImportError importing .pyd - DLL load failed. Cython

I am trying to Cythonize this code (GDTest.pyx):

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

Here is my setup.py:

from distutils.core import setup
from Cython.Build import cythonize
import numpy

setup(
    ext_modules=cythonize('GDTest.pyx'),
    include_dirs=[numpy.get_include()]
)

When I run the line:

python setup.py -c mingw64 --inplace

I get a bunch of warnings (deprecated numpy API, and a few related to _Pyx_RaiseTooManyValuesError) but then it creates GDTest.pyd. When I try to import it, I get the error:

ImportError:DLL Load Failed: A dynamic link library (DLL) initialization routine failed.

I ran dependency walker and this is what it has listed as missing:

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

The odd thing is that if I try to import it a second time (import GDTest) it works. Any thoughts on how to fix this issue?

Thanks!

Upvotes: 4

Views: 2620

Answers (1)

hashimba
hashimba

Reputation: 63

I fixed my issue by completely uninstalling canopy. Then, I installed a 32-bit version of anaconda and MS visual studio 2008 express edition. It works now. Hooray!

Upvotes: 1

Related Questions