最好的方法是把python代码编译成so文件,再用一个py脚本去调用
from distutils.core import setup from Cython.Build import cythonize def py2c(file): # 返回distutils.extension.Extension对象列表 cpy = cythonize(file) setup( name = 'pyd_release', # 包名称 version = "1.0", # 包版本号 ext_modules= cpy, # 扩展模块 author = "zc",#作者 author_email='sss@xxx.com' #作者邮箱 ) if __name__ == '__main__': file = "你的代码.py" py2c(file)
使用下面的代码进行运行
python gen_pyd.py build_ext --inplace
之后在linux上会生成对应的so文件
如果在windows上会生成对应的pyd文件
调用方法
import 你的代码 if __name__ == '__main__': 你的代码.start_server(ip="localhost",way="gpu")