简体   繁体   中英

pybind11 both python 2.7 and 3.6

I'm trying to work with pybind11 and create my library.so for both python2.7 and python3.6. I'm using the cmake package to use pybind11 but can implement my own as well.

As far as I can see, I need to specify the python version I use when I install pybind. I need to specify that so add_pybind11_module would know with which python to link etc. In addition, I can create the so on my own using g++ and create both so's.

In addition, I need to create the so's in different folders because their names are the same.

I guess there is already an existing solution for this problem. Is there a built in support in pybind11 or is someone did a cmake plugin for it?

Thank you

You need to build your extension twice and generate two .so files. You can do it with simple bash script, it would be something like that:

# build module for 3.6 
mkdir -p build-python-3.6
(cd build-python-3.6 ; cmake .. -DPYBIND11_PYTHON_VERSION=3.6 ; make )

# build module for 2.7
mkdir -p build-python-2.7
(cd build-python-2.7 ; cmake .. -DPYBIND11_PYTHON_VERSION=2.7 ; make )

pybind11 includes python version in library name by default, therefore you should be able to have them in the same folder (eg my_library.cpython-37m-x86_64-linux-gnu.so ). While it might work I would suggest you to write a setup.py and let setuptools to place your library in appropriate place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM