Reputation: 1
1- I build a file 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"),)
I want to convert python to cyth but it shows an error
'test_cy.pyx' doesn't match any files
Could you please tell me what should I do now? Where should I save these two files?
Upvotes: 0
Views: 372
Reputation: 498
There are 4 steps to converting a python script to Cython:
1) write the script in python and create bridges to statically type C (ie. declare your variables like so:
x = 0 # python version
cdef int x = 0 # cython declare
You don't have to but this is one way to speed up a python script with cython. Then save your file with .pyx extension (in your ex test_cy.pyx).
2) write a setup file (ex: mysetup.py) that has the following in it:
from distutils.core import setup
from Cython.Build import cythonize
setup(name='Test One', ext_modules=cythonize("test_cp.pyx"),)
3) compile in you cmd:
python mysetup.py build_ext --inplace
4) create a separate python module (ex: run_code.py) and import your .pyx code:
from test_cy import test
# now use the function that was in your .pyx code
Upvotes: 1