将 Numpy 添加到绑定包中
要将 Numpy 添加到包中,请使用 include_dirs 关键字修改 setup.py,并在包装器 Python 脚本中导入 numpy 以通知 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()