使用boost.python和pybind11 创建Python3的64bit module

1.首先Boost.python默认的windows binary包都是针对python2.7的,要开发python3的库只能从源码重新编译
2.下载boost 1.62源代码, 解压缩后,执行bootstrap.bat
3.编辑user-config.jam,指定使用VS2015和python 3.6编译

# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 14.0 ;

using python : 3.6 : C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36 : C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\include : C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36\\libs ;

注意 user-config.jam要放到C:\Users\Administrator\目录下

4.执行 bjam --with-python --prefix=c:\boost stage toolset=msvc-14.0 variant=release link=shared address-model=64 threading=multi runtime-link=shared install

5.编译后会生成boost*.dll,要放到C:\windows\System32目录下
6.创建Windows DLL工程,参考默认的Hello_ext,注意编译后的dll的名称一定要跟python module的名称一致,dll要改成pyd的后缀,可以放到python的安装目录的DLLs目录下,名称不一致的话,python会找不到module,这里卡了我好长时间,另外编译时要link boost的库以及python3.6的lib和include文件。

最近发现pybind11比boost.python好用,因为不需要依赖boost的库,只需要引用一下pybind的头文件就行了,最重要的是帮助文档写的很详细,比boost.python的文档写的好多了。