将python函数转换为cython



我有一个基本的string manip函数在' ' ' ' python ' ' '

def str_process(string_list):
op = []
for each_str in string_list:
op.append(each_str+"_random token")
return op

可以正常工作。但是当我尝试在cython中运行相同的函数时:

import cython
cdef list func(list string_list):
cdef list op =[]
cdef str each_str
for each_str in string_list:
op.append(each_str+"_random token")
return op

我把上面的cython function放在test.pyx文件中,并使用下面的

调用它
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize('test.pyx'))

错误:

option -f not recognized

我是一个全新的cython,任何错误的建议将是伟大的。

我能够使用python3 setup.py build_ext --inplace命令成功地对代码进行cythonized。看起来您只是错误地运行了setup.py文件。

此外,除非您有更多的代码,否则您不需要在.pyx文件中导入cython。

最新更新