我正在尝试将此代码Cythonize(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

这是我的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()]
)

当我运行线路时:
python setup.py -c mingw64 --inplace

我收到了一堆警告(不推荐使用的numpy api,以及一些与_Pyx_RaiseTooManyValuesError相关的警告),但随后它创建了GDTest.pyd。当我尝试导入它时,我得到错误:
ImportError:DLL Load Failed: A dynamic link library (DLL) initialization routine failed.

我运行了dependency walker,这是它列出的缺少的:
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

奇怪的是,如果我第二次尝试导入它(import GDTest),它就会工作。对如何解决这个问题有什么想法吗?
谢谢!

最佳答案

我通过完全卸载Canopy解决了我的问题。然后,我安装了32位版本的anaconda和msvisualstudio2008速成版。现在可以了万岁!

07-26 06:49