Complie .pyx到.pyd包含相对导入

时间:2016-10-18 08:38:40

标签: python scikit-learn cython cythonize

这是我学习sklearn的问题。 sklearn中有一些cython代码,例如:

 sklearn/tree/
     _utils.pyd
     _tree.pyd
     _test.pyx

_test.pyx包含代码:

   from ._utils cimport log

现在我想使用Cython将_test.pyx编译为_test.pyd。 但它不起作用,错误是:

Error compiling Cython file:
------------------------------------------------------------
...

import numpy as np
cimport numpy as np
np.import_array()

from ._utils cimport log
^
------------------------------------------------------------

sklearn\tree\_test.pyx:30:0: 'sklearn\tree\_utils.pxd' not found

以下是cythonbuild.py中的编译代码:

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

extensions = [
    Extension("tree", ["_criterion.pyx"],
        include_dirs = [numpy.get_include()],
)
]
setup(
    name = "test",
    ext_modules = cythonize(extensions),
)

然后我在cmd中运行命令:

python cythonbuild build_ext --inplace

如何解决此问题?

0 个答案:

没有答案