Python 看不到用 Cython 编写的带有 .pyx 扩展名的模块

问题描述 投票:0回答:0

当我尝试在 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 文件中。

python import module cython
© www.soinside.com 2019 - 2024. All rights reserved.