【问题标题】:Convert python function to cython将python函数转换为cython
【发布时间】:2021-08-04 22:38:34
【问题描述】:

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

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 的新手,任何关于错误的建议都会很棒。

【问题讨论】:

    标签: python cython cythonize


    【解决方案1】:

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

    此外,除非您有更多未在此示例中显示的代码,否则您无需在 .pyx 文件中导入 cython。

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 2020-04-19
      • 2020-07-17
      • 1970-01-01
      相关资源
      最近更新 更多