I have a C++ Library with Python Bindings built as follows, and a Python Binary that needs to import the libPerceptionPybind.so
that is generated.
JavaScript
x
24
24
1
package(default_visibility = ["//visibility:public"])
2
load("@pip_pybind//:requirements.bzl", "requirement")
3
4
cc_binary(
5
name = "PerceptionPybind",
6
srcs = ["PerceptionPybind.cpp"],
7
deps = [
8
"@pybind11",
9
"@libtorch_cpu//:torch_cpu",
10
],
11
linkshared = True,
12
)
13
14
py_binary(
15
name = "TestPerceptionPybind",
16
srcs = [ "TestPerceptionPybind.py" ],
17
deps = [
18
":PerceptionPybind"
19
requirement("numpy"),
20
requirement("torch")
21
],
22
23
)
24
I see that the libPerceptionPybind.so has been generated in my bazel-bin/pybind
folder. I tried to add PerceptionPybind
to the deps as you can see, but it gives an error:
JavaScript
1
2
1
//pybind:PerceptionPybind' does not have mandatory providers: 'py' or 'PyInfo
2
Advertisement
Answer
You can use the data
field to have your dynamic library copied into the Python binary target folder:
JavaScript
1
12
12
1
py_binary(
2
name = "TestPerceptionPybind",
3
srcs = [ "TestPerceptionPybind.py" ],
4
deps = [
5
requirement("numpy"),
6
requirement("torch")
7
],
8
data = [
9
":PerceptionPybind",
10
],
11
)
12