0

我有一个 C++ 库,其中包含如下构建的 Python 绑定,以及一个需要导入libPerceptionPybind.so生成的 Python 二进制文件。

package(default_visibility = ["//visibility:public"])
load("@pip_pybind//:requirements.bzl", "requirement")

cc_binary(
    name = "PerceptionPybind",
    srcs = ["PerceptionPybind.cpp"],
    deps = [
        "@pybind11",
        "@libtorch_cpu//:torch_cpu",
    ],
    linkshared = True,
)

py_binary(
    name = "TestPerceptionPybind",
    srcs = [ "TestPerceptionPybind.py" ],
    deps = [
        ":PerceptionPybind"
        requirement("numpy"),
        requirement("torch")
    ],
    
)

我看到 libPerceptionPybind.so 已在我的bazel-bin/pybind文件夹中生成。PerceptionPybind如您所见,我尝试添加 到 deps 中,但它给出了错误:

//pybind:PerceptionPybind' does not have mandatory providers: 'py' or 'PyInfo
4

1 回答 1

0

您可以使用该data字段将动态库复制到 Python 二进制目标文件夹中:

py_binary(
    name = "TestPerceptionPybind",
    srcs = [ "TestPerceptionPybind.py" ],
    deps = [
        requirement("numpy"),
        requirement("torch")
    ],
    data = [
        ":PerceptionPybind",
    ],
)
于 2021-07-12T05:32:30.780 回答