python打包成so文件过程解析
作者:AnswerThe 时间:2022-03-19 18:08:46
这篇文章主要介绍了python打包成so文件过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install cython
编写setput.py文件:
setup.py文件内容如下:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [Extension("ln_facedetector",
["ln_facedetector.py"],
include_dirs=["/usr/local/lib"],
libraries=["/usr/local/lib/python3.6/site-packages/cv2/cv2.cpython-36m-x86_64-linux-gnu.so",
"/usr/local/lib/python3.6/site-packages/dlib.cpython-36m-x86_64-linux-gnu.so"],
library_dirs=["/usr/local/lib/python3.6/site-packages/cv2","/usr/local/lib/python3.6/site-packages"])]
setup(ext_modules=cythonize(extensions))
整个工程中包括多少个py文件,就写多少个Extension,并把需要调用的其他库路径在include_dirs、libraries、library_dirs中进行设置。
编译so文件,执行以下命令:
python setup.py build_ext
调用so文件:
import sys
sys.path.append('/vloum/faceSO/ln_facedetector') #加载so文件(入参为so文件路径)
from ln_facedetector import faceutil #import so文件中的相关类
arr = faceutil.detection("/vloum/faceSO/a.jpg")
print(arr)
来源:https://www.cnblogs.com/answerThe/p/11600590.html
标签:python,打包,so,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python文件读写保存操作的示例代码
2022-03-20 01:21:23
asp如何设置cookie的过期时间
2008-02-29 13:36:00
关于团队建设以及网站建设的琐事
2009-03-19 13:31:00
用Python编写一个每天都在系统下新建一个文件夹的脚本
2021-11-08 22:39:16
一文带你掌握Python中文词频统计
2022-11-17 21:02:00
![](https://img.aspxhome.com/file/2023/0/66880_0s.png)
当视觉设计师遇上产品经理、开发工程师…[译]
2010-01-17 10:18:00
![](https://img.aspxhome.com/file/UploadPic/20101/17/gui_vs_pm_01-86s.jpg)
python爬虫 urllib模块发起post请求过程解析
2022-02-07 22:52:53
![](https://img.aspxhome.com/file/2023/8/69608_0s.png)
Python web如何在IIS发布应用过程解析
2022-10-17 16:02:51
pandas创建DataFrame的方式小结
2021-10-25 13:26:23
![](https://img.aspxhome.com/file/2023/2/86632_0s.png)
泛泛而谈界面视觉效果的一致性
2010-01-05 17:05:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/0912-ui-conformity-5-22s.jpg)
python调用接口的4种方式代码实例
2022-01-15 17:03:30
Python实现七大查找算法的示例代码
2021-05-28 07:33:35
![](https://img.aspxhome.com/file/2023/9/77779_0s.jpg)
15个网页排版例子赏析
2008-01-06 16:38:00
![](https://img.aspxhome.com/file/UploadPic/20081/6/20081616479963s.gif)
带你深入了解MySQL语句优化的基本原则
2008-11-27 17:00:00
一段有趣的js代码的研究
2008-04-29 21:47:00
PHP中常用的数组操作方法笔记整理
2023-06-06 15:17:12
![](https://img.aspxhome.com/file/2023/4/55484_0s.jpg)
SQL语句参考及记录集对象详解
2008-11-25 11:47:00
XMLHttpRequest的浏览器兼容代码写法
2008-09-02 10:46:00
php处理抢购类功能的高并发请求
2023-11-21 01:30:54
![](https://img.aspxhome.com/file/2023/6/94496_0s.jpg)
[译稿]Web 字体的未来
2008-07-31 17:50:00