cython Bundling a Cython program using pyinstaller


Start from a Cython program with a entrypoint:

def do_stuff():
    cdef int a,b,c
    a = 1
    b = 2
    c = 3
    print("Hello World!")
    input("Press Enter to continue.")

Create a file in the same folder:

from distutils.core import setup
from Cython.Build import cythonize
    name = "Hello World",
    ext_modules = cythonize('program.pyx'), 

Running it with python build_ext --inplace will produce a .pyd library in a subfolder.

After that, create a vanilla Python script using the library (e.g., and put the .pyd file beside it:

import program

Use PyInstaller to bundle it pyinstaller --onefile "". This will create a subfolder containing the executable of a 4 MB+ size containing the library plus the python runtime.