把python 文件编译成.so 文件

  • 所需要的包Cython
  • pip install Cython
  • 打包文件so_test.py
def test():
	print("hello world")
  • setup.py中的内容如下
from distutils.core import setup

from Cython.Build import cythonize

setup(ext_modules=cythonize(['so_test.py']))

在bash 中运行
python setup.py build_ext

运行完之后 把so_test.so 文件copy 出来就可以用了。和往常导包一样

  • demo.py
from so_test import test
test()

在这里插入图片描述

发布了127 篇原创文章 · 获赞 25 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_44224529/article/details/104238107