1

我尝试使这个示例工作,但是每次我尝试使用 bazel 构建程序时,都会收到以下错误消息:

bazel build //code:label_image 
ERROR: /home/jonas/tensorflow/code/BUILD:12:1: no such package 'tensorflow': BUILD file not found on package path and referenced by '//code:label_image'.
ERROR: /home/jonas/tensorflow/code/BUILD:12:1: no such package 'tensorflow': BUILD file not found on package path and referenced by '//code:label_image'.
ERROR: /home/jonas/tensorflow/code/BUILD:12:1: no such package 'tensorflow': BUILD file not found on package path and referenced by '//code:label_image'.
ERROR: /home/jonas/tensorflow/code/BUILD:12:1: no such package 'tensorflow': BUILD file not found on package path and referenced by '//code:label_image'.
ERROR: /home/jonas/tensorflow/code/BUILD:12:1: no such package 'tensorflow': BUILD file not found on package path and referenced by '//code:label_image'.
ERROR: Analysis of target '//code:label_image' failed; build aborted.
INFO: Elapsed time: 1.261s

我将来自 github 的确切源代码保存在一个名为code. 我通过 pip: 安装tensorflow在(活动)虚拟环境中pip3 install --upgrade tensorflow。我使用拱 linux。

为什么 bazel 找不到合适的包?我对 bazel/tensorflow 很陌生。这些包保存在哪里?我必须在某处明确指定它们吗?

4

1 回答 1

3

通常,从使用 Bazel 的项目中提取子文件夹并单独构建它是行不通的。

如果您查看该文件label_image夹的 BUILD 文件,您将看到 C++ 二进制文件的以下定义:

cc_binary(
    name = "label_image",
    srcs = [
        "main.cc",
    ],
    linkopts = select({
        "//tensorflow:android": [
            "-pie",
            "-landroid",
            "-ljnigraphics",
            "-llog",
            "-lm",
            "-z defs",
            "-s",
            "-Wl,--exclude-libs,ALL",
        ],
        "//conditions:default": ["-lm"],
    }),
    deps = select({
        "//tensorflow:android": [
            # cc:cc_ops is used to include image ops (for label_image)
            # Jpg, gif, and png related code won't be included
            "//tensorflow/cc:cc_ops",
            "//tensorflow/core:android_tensorflow_lib",
            # cc:android_tensorflow_image_op is for including jpeg/gif/png
            # decoder to enable real-image evaluation on Android
            "//tensorflow/core/kernels:android_tensorflow_image_op",
        ],
        "//conditions:default": [
            "//tensorflow/cc:cc_ops",
            "//tensorflow/core:core_cpu",
            "//tensorflow/core:framework",
            "//tensorflow/core:framework_internal",
            "//tensorflow/core:lib",
            "//tensorflow/core:protos_all_cc",
            "//tensorflow/core:tensorflow",
        ],
    }),
)

这条规则告诉 Bazellabel_image需要构建什么二进制文件。值得注意的是,它具有指向 tensorflow 工作空间(由文件定义)的根目录的依赖项 ( deps) 和链接选项 ( ) ,而您提取的子文件夹中缺少该根目录。这就是 Bazel 抱怨找不到包裹的原因。linkopts//tensorflowWORKSPACEtensorflow

构建二进制文件的最简单方法label_image是从 tensorflow 项目中构建它,因为路径已经设置好了。

于 2017-09-21T21:28:21.023 回答