1. Installation: pip install cython
  2. Write the cython file â€Ķ it MUST end in .pyx ~ex.: function.pyx, (Instead of a normal python function file ~ex.: function.py)
  3. Create a setup.py file with the following code:
    from setuptools import setup
    from Cython.Build import cythonize
    setup(
       ext_modules = cythonize('function.pyx')
    )
  4. Open the terminal end run the following command: python setup.py build_ext --inplace
  5. 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 .pyx files in my folder, all others files created need to be in the src/ folder.
  • 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