cython Cython bundling Adding Numpy to the bundle


Example

To add Numpy to the bundle, modify the setup.py with include_dirs keyword and necessary import the numpy in the wrapper Python script to notify Pyinstaller.

program.pyx:

import numpy as np
cimport numpy as np


def do_stuff():
    print("Hello World!")
    cdef int n
    n = 2
    r = np.random.randint(1,5)
    print("A random number: "+str(r))
    print("A random number multiplied by 2 (made by cdef):"+str(r*n))
    input("Press Enter to continue.")

setup.py:

from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

setup(
    ext_modules=cythonize("hello.pyx"),
    include_dirs=[numpy.get_include()]
)

main.py:

import program
import numpy
program.do_stuff()