我有一个pybind11库,里面定义了类和函数。在导入时,我需要调用一些python来初始化python路径等。
import my_pybind11
# I would like it to causes my_init to be called...
# if it were straight python I would just put
def my_init():
sys.paths.append('hope/you/can/help')
my_init()
# in the body of the library source. 我不确定如何在使用主要是c++ &绑定的pybind11库时获得同样的效果。
发布于 2021-04-07 04:28:32
最后,我采用了将pybind11 C++包装库重命名为_my_pybind11的方法
并添加了一个my_pybind11.py:
from _my_pybind11 import *
def my_init():
sys.paths.append('hope/you/can/help')
my_init()这允许我将一些纯c++与pybind11构建的python库捆绑在一起。
https://stackoverflow.com/questions/66954989
复制相似问题