我按照说明执行了每一步,但它仍然无法构建
https://www.tensorflow.org/install/source_windows

  • 我不能包含 CUDA 库和包含文件,因为 python 脚本在 ./configure.py 阶段无法识别 2 个逗号分隔的路径
    它只识别我输入的第一个,你可以看到我以相反的顺序输入它们,它看到第一个就好了。 Afaik 这是一个新增功能,因为说明在不同时间要求路径。

    请指定您要使用的 CUDA SDK 版本。 [留空默认为CUDA 10]:
    Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]:
    
    Please specify the comma-separated list of base paths to look for CUDA libraries and headers. [Leave empty to use the default]: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include, C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64
    
    Could not find any cudart.lib in any subdirectory:
    ''
    'lib64'
    'lib'
    'lib/-linux-gnu'
    'lib/x64'
    'extras/CUPTI/'
    of:
    'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include'
    Asking for detailed CUDA configuration...
    
    Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10]:
    
    Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]:
    
    Please specify the comma-separated list of base paths to look for CUDA libraries and headers. [Leave empty to use the default]: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include
    
    Could not find any cuda.h matching version '10' in any subdirectory:
    ''
    'include'
    'include/cuda'
    'include/*-linux-gnu'
    'extras/CUPTI/include'
    'include/cuda/CUPTI'
    of:
    Asking for detailed CUDA configuration...
    

  • 所以我必须禁用 CUDA 支持
    然后我只是想构建 DLL
    我得到了一堆错误
    > C:\Temp\tensorflow-master>bazel build --config=opt //tensorflow:tensorflow.dll
    > WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
    > INFO: Options provided by the client:
    >   Inherited 'common' options: --isatty=1 --terminal_columns=120
    > INFO: Options provided by the client:
    >   'build' options: --python_path=C:/ProgramData/Anaconda3/python.exe
    > INFO: Reading rc options for 'build' from c:\temp\tensorflow-master\.bazelrc:
    >   'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone --strategy=Genrule=standalone -c opt --announce_rc --define=grpc_no_ares=true --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include
    > INFO: Reading rc options for 'build' from c:\temp\tensorflow-master\.tf_configure.bazelrc:
    >   'build' options: --action_env PYTHON_BIN_PATH=C:/ProgramData/Anaconda3/python.exe --action_env PYTHON_LIB_PATH=C:/ProgramData/Anaconda3/lib/site-packages --python_path=C:/ProgramData/Anaconda3/python.exe --config monolithic --copt=-w --host_copt=-w --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN --copt=-DNOGDI --host_copt=-DNOGDI --verbose_failures --distinct_host_configuration=false --action_env TF_CONFIGURE_IOS=0
    > INFO: Found applicable config definition build:monolithic in file c:\temp\tensorflow-master\.bazelrc: --define framework_shared_object=false
    > INFO: Found applicable config definition build:opt in file c:\temp\tensorflow-master\.tf_configure.bazelrc: --copt=/arch:AVX --define with_default_optimizations=true
    > INFO: An error occurred during the fetch of repository 'com_google_protobuf'
    > INFO: Call stack for the definition of repository 'com_google_protobuf':
    >  - C:/temp/tensorflow-master/tensorflow/workspace.bzl:432:5
    >  - C:/temp/tensorflow-master/WORKSPACE:26:1
    > ERROR: Skipping '//tensorflow:tensorflow.dll': error loading package 'tensorflow': in C:/temp/tensorflow-master/tensorflow/core/platform/default/build_config.bzl: Encountered error while reading extension file 'protobuf.bzl': no such package '@com_google_protobuf//': Traceback (most recent call last):
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 104
    >                 _apply_patch(ctx, ctx.attr.patch_file)
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 70, in _apply_patch
    >                 _wrap_bash_cmd(ctx, patch_command)
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 28, in _wrap_bash_cmd
    >                 fail("BAZEL_SH environment variable i...")
    > BAZEL_SH environment variable is not set
    > WARNING: Target pattern parsing failed.
    > ERROR: error loading package 'tensorflow': in C:/temp/tensorflow-master/tensorflow/core/platform/default/build_config.bzl: Encountered error while reading extension file 'protobuf.bzl': no such package '@com_google_protobuf//': Traceback (most recent call last):
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 104
    >                 _apply_patch(ctx, ctx.attr.patch_file)
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 70, in _apply_patch
    >                 _wrap_bash_cmd(ctx, patch_command)
    >         File "C:/temp/tensorflow-master/third_party/repo.bzl", line 28, in _wrap_bash_cmd
    >                 fail("BAZEL_SH environment variable i...")
    > BAZEL_SH environment variable is not set
    > INFO: Elapsed time: 21.498s
    > INFO: 0 processes.
    > FAILED: Build did NOT complete successfully (0 packages loaded)
    >     currently loading: tensorflow
    

    我已经按照 github 上的一个问题中的建议添加到 WORKSPACE 文件的顶部
    http_archive(
        name = "io_bazel_rules_docker",
        sha256 = "87fc6a2b128147a0a3039a2fd0b53cc1f2ed5adb8716f50756544a572999ae9a",
        strip_prefix = "rules_docker-0.8.1",
        urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.8.1.tar.gz"],
    )
    

    我如何克服这些错误?

    以及为什么对 C++ 的支持这么差,据我所知,每个人都使用 tensorflow 和 C++ 进行推理。我无法想象所有的自动驾驶汽车都在 python 上运行

    最佳答案

    通过运行命令修复

    c:\msys32\usr\bin\sed -ri "/^\W+sha256 = \"[^\"]+\"\W+$/d" tensorflow/workspace.bzl
    

    完全禁用校验和验证 https://github.com/tensorflow/tensorflow/issues/12979

    然后我还需要做
    c:\msys32\usr\bin\pacman.exe -S git patch unzip
    

    并添加 BAZEL_SH 环境变量 c:\msys32\usr\bin\bash.exe

    关于python - 无法在 Windows 中构建 tensorflow C++ API,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57503584/

    10-09 07:24
    查看更多