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