- Installation:
pip install cython - Write the cython file âĶ it MUST end in
.pyx~ex.:function.pyx, (Instead of a normal python function file ~ex.:function.py) - Create a
setup.pyfile with the following code:from setuptools import setup from Cython.Build import cythonize setup( ext_modules = cythonize('function.pyx') ) - Open the terminal end run the following command:
python setup.py build_ext --inplace - It will build a binary file, somenthing like
function.cp39-win_amd64.pyd, than import it normally with:import function
This is the basic folder structure for this implementation
python package/
âââ main.py
âââ sub_package/
âââ __init__.py
âââ src/
âââ cython_module.pyx
âââ setup.py
âââ cython_module.c
âââ ...
With my custom folder structuren (NOT WORKING)
python package/
âââ main.py
âââ sub_package/
âââ __init__.py
âââ cython_module.pyx
âââ src/
âââ setup.py
âââ cython_module.c
âââ ...
- Objectives:
- I want to see only the
.pyxfiles in my folder, all others files created need to be in thesrc/folder.
- I want to see only the
- Useful link:
Code for the setup.py file:TODO
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize('function.pyx')
)Command for the terminal:TODO
python setup.py build_ext --inplace