python代码怎么封装成dll_python – 如何将链接的DLL和pyd文件打包成一个自包含的pyd文件?...

Python的包装&我们许多人的部署仍然是一个痛点.没有一个银弹.这里有几种方法:

OpenCV构建方法

OpenCV generates these wrapper functions automatically from the C++

headers using some Python scripts which are located in

modules/python/src2.

基本上,它解析头文件,并在需要时生成静态PyObject关键字.一旦标题被适当地创建,它只是调用python设置.老实说,这可能是有效的,但我不会建议这种方法.

2.文件

如果您已经使用Makefile,只需创建一个规则来放置您的lib协议.例如,从我自己的代码:

setup.py

from distutils.core import setup, Extension

setup(name='sha1_hmac', version='1.0', \

ext_modules=[Extension('sha1_hmac',

library_dirs=['C:\MinGW\lib'],

sources= ['../tools/sha1.c','sha1_hmac.c'])])

Makefile

# The hmac generation used by the webserver is done

# using the sha1.c implementation. There is a binding needed to

# glue the C code with the python script

libsha1_hmac:

ifeq ($(OS), Windows_NT)

$(PYTHON) setup.py build --compiler=mingw32

else

$(PYTHON) setup.py install --home=$(CURDIR)

endif

.PHONY: webserver

webserver: libsha1_hmac

ifeq ($(OS), Windows_NT)

mv $(shell find build -type f -name "sha1*.pyd") $(LIB)

else

mv -f $(shell find $(LIB)/python -type f -name "sha1*.so") $(LIB)

endif

$(PYTHON) hmac_server.py

现代部署工具

有几个新的工具可以部署python应用程序,即看起来有吸引力的轮子.我不使用它,但它看起来像它可以缓解您的捆绑问题:

一旦轮换,您可以像这样安装:pip install some-package.whl

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值