pythonboost-python

How to make python3 import examine .so and ...-g.so as well?


We expose C++ code to python via boost.python. We produce release and debug builds.

release builds produce lib.so files

debug builds produce lib-g.so files.

Our python code then

import lib<mymodule>

Is there a way to place a hook such that those import statements can explore both libmymodule.so and if not found libmymodule-g.so?


Solution

  • Try the following:

    import importlib
    
    try:
        import libmymudule
    except ImportError:
        libmymudule = importlib.import_module("libmymudule-g")