我是python的初学者,我也刚刚熟悉cython。我正在Windows 64位系统上使用python3.7
1-我构建了一个文件我是python的初学者,我也刚刚熟悉cython。我正在Windows 64位系统上使用python3.7,python,cython,cythonize,Python,Cython,Cythonize,1-我构建了一个文件test_cy.pyx def test(x) y=0 for i in range(x): y+=1 return y from Cython.Build import cythonize setup(ext_modules=cythonize("test_cy.pyx"),) 我想将python转换为cyth,但它显示了一个错误 'test_cy.pyx' doesn't match any files 你能告诉我现在该怎么
test_cy.pyx
def test(x)
y=0
for i in range(x):
y+=1
return y
from Cython.Build import cythonize
setup(ext_modules=cythonize("test_cy.pyx"),)
我想将python转换为cyth,但它显示了一个错误
'test_cy.pyx' doesn't match any files
你能告诉我现在该怎么办吗?这两个文件应该保存在哪里?将python脚本转换为Cython需要4个步骤: 1) 用python编写脚本,并创建静态类型C的桥接(即声明变量,如下所示:
x = 0 # python version
cdef int x = 0 # cython declare
您不必这样做,但这是使用cython加速python脚本的一种方法,然后使用.pyx扩展名保存文件(在ex test_cy.pyx中)
2) 编写一个包含以下内容的安装文件(例如:mysetup.py):
from distutils.core import setup
from Cython.Build import cythonize
setup(name='Test One', ext_modules=cythonize("test_cp.pyx"),)
3) 在cmd中编译:
python mysetup.py build_ext --inplace
4) 创建一个单独的python模块(例如:run_code.py)并导入.pyx代码:
from test_cy import test
# now use the function that was in your .pyx code
1-现在我创建了一个名为test_cy.pyxcdef int test(cdef int x)cdef int y=0 cdef int i,用于范围(x):y+=1 return yan的文件,然后我创建了我的设置文件,正如您在上面从Cython的distutils.core导入设置中创建的一样。构建导入cythonize设置(name='test One',ext_modules=cythonize(“test_cy.pyx”),)您是否在与文件相同的目录中运行步骤3中的cmd行?