当我尝试在 Python 文件中导入在 Cython 上编写的模块时,引发了异常:
ModuleNotFoundError: No module named 'run_cython'
Python 和 Cython 位于一个目录中。
设置.py:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('run_cython.pyx'))
run_cython.pyx:
cpdef int test(int x):
cdef int y = 1
cdef int i
for i in range(1, x+1):
y *= i
return y
python 文件:
import run_cython
number = run_cython.test(10)
print(number)
我需要将 cython 模块导入到 python 文件中。