【问题标题】:Bazel, how to add Python library built in C++ into Python Binary?Bazel,如何将 C++ 中内置的 Python 库添加到 Python 二进制文件中?
【发布时间】:2021-07-11 02:08:49
【问题描述】:

我有一个 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

【问题讨论】:

    标签: python bazel bazel-rules


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      相关资源
      最近更新 更多