How to bundle external CMake dependencies to generate a Python package?

321 views Asked by At

I am trying to generate Python bindings for the OpenVSlam project.

I am using PyBind11 and following the cmake_example template.

I successfully build the .so file using pybind11_add_module in my development environment, in which I have all dependencies installed (libraries such as OpenCV, Protobuf, etc...). The .so file works well in this development environment. I can run import sys; sys.path.append('.'); import openvslam_python; and use the binding functions properly. However, I would like to ship the .so file as a Python package.

The problem is that when I run python3 setup.py sdist bdist_wheel and try to install the resulting wheel on another environment (without the installed dependencies) it says it cannot find the dependencies' .so files. For example, it outputs the following error (in a Docker container):

>>> import sys
>>> sys.path.append('.')
>>> import openvslam_python
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libopenvslam.so: cannot open shared object file: No such file or directory

I would like to know if there is a way of bundling the dependencies of the PyBind11 bindings with CMake (or maybe inside the setup.py script) to be able to install them in environments that do not have any of the dependencies installed. This way, I could install the bindings anywhere with a simple pip install command.

0

There are 0 answers