我的目标:
我想创建一个类似dll的文件,其中包含运行功能(我的源代码,numpy,sklearn)所需的所有代码nad模块
我尝试过的事情:
详细信息:
cimport numpy as np
import numpy as np
from sklearn import datasets, linear_model
def run():
diabetes = datasets.load_diabetes()
diabetes_X = diabetes.data[:, np.newaxis, 2]
diabetes_X_train = diabetes_X[:-20]
diabetes_X_test = diabetes_X[-20:]
diabetes_y_train = diabetes.target[:-20]
regr = linear_model.LinearRegression()
regr.fit(diabetes_X_train, diabetes_y_train)
return regr.predict(diabetes_X_test)
然后我创建了一个setup.py来创建.pyd 在 working_dir 中,我有numpy和sklearn 用于Python扩展包的非官方Windows二进制文件
from setuptools import find_packages
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [
Extension("cysk", ["cysk.pyx"],
include_dirs = ['working_dir/numpy/core/include'])
]
setup(
name = 'cysk.pyx',
ext_modules = cythonize(extensions),
packages = find_packages('working_dir')
)