將 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()