简体   繁体   English

无法在 Windows 中构建 tensorflow C++ API

[英]Cannot build the tensorflow C++ API in windows

I followed every step on the instructions and it still won't build https://www.tensorflow.org/install/source_windows我按照说明进行了每一步操作,但仍然无法构建https://www.tensorflow.org/install/source_windows

  1. I cannot include the CUDA library and include files, because the python script won't recognize 2 comma separated paths during ./configure.py stage It only recognizes the first one I enter, as you can see I entered them in reverse order and it see the first one just fine.我无法包含 CUDA 库和包含文件,因为在 ./configure.py 阶段,python 脚本无法识别 2 个逗号分隔的路径它只识别我输入的第一个路径,正如您所看到的,我以相反的顺序输入它们并且它看第一个就好了。 Afaik this is a new addition, because the instructions ask for path at different times. Afaik 这是一个新增功能,因为说明在不同时间要求路径。

    Please specify the CUDA SDK version you want to use.请指定您要使用的 CUDA SDK 版本。 [Leave empty to default to CUDA 10]: [留空默认为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...

So I have to disable CUDA support Then Im just trying to just build the DLL and I get this mess of errors所以我必须禁用 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

I already added to the top of WORKSPACE file as suggested in one of the issues on github我已经按照 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"],
)

How do I get past these errors?我如何克服这些错误?

And why is there such poor support for C++, as far as I know everyone uses tensorflow with C++ to do inference.以及为什么对 C++ 的支持这么差,据我所知,每个人都使用 tensorflow 和 C++ 进行推理。 I can't imagine all the self-driving cars are running on python我无法想象所有的自动驾驶汽车都在 python 上运行

Fixed by running command通过运行命令修复

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

Which disables checksum validation completely https://github.com/tensorflow/tensorflow/issues/12979完全禁用校验和验证https://github.com/tensorflow/tensorflow/issues/12979

Then I also needed to do然后我还需要做

c:\msys32\usr\bin\pacman.exe -S git patch unzip

and add the BAZEL_SH environment variable c:\\msys32\\usr\\bin\\bash.exe并添加 BAZEL_SH 环境变量c:\\msys32\\usr\\bin\\bash.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM