WindowsでTensorFlow liteをビルドする

#はじめに
　[こういう事](https://qiita.com/kumaS-kumachan/items/050a90e0fcfd7e9aa3cf)で、PoseNetをデスクトップ環境で使いたいとなったけど、いろいろ大変だったのでここに書きます。PoseNetの移植については書きません。タイトルのことのみ書きます。もし、PoseNetを移植したければ、以下のページを参考にしてください。
・[Posenet (TensorFlow Lite) のヒートマップをOpenGLESで可視化](https://qiita.com/terryky/items/5163d8893a521d005df0)

#Bazelをインストール
　[公式ページ](https://bazel.build/)を参考にインストールしていきます。必須なものは以下です。

* [Visual C++ Redistributable for Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48145)
* [Bazel binary](https://github.com/bazelbuild/bazel/releases)

　ただし、場合によっては Visual C++ Redistributable for Visual Studio 2015 はすでにインストールされているかもしれません。
　適当なところにbazelを解凍し、解凍したフォルダにパスを通します。そして、コマンドプロンプトで以下のようなコマンドを打ち、こんな感じで返ってきたら成功です。

```console
C:>bazel -help
                                                           [bazel release 2.2.0]
Usage: bazel <command> <options> ...

Available commands:
  analyze-profile     Analyzes build profile data.
  aquery              Analyzes the given targets and queries the action graph.
  build               Builds the specified targets.
  canonicalize-flags  Canonicalizes a list of bazel options.
  clean               Removes output files and optionally stops the server.
  coverage            Generates code coverage report for specified test targets.
  cquery              Loads, analyzes, and queries the specified targets w/ configurations.
  dump                Dumps the internal state of the bazel server process.
  fetch               Fetches external repositories that are prerequisites to the targets.
  help                Prints help for commands, or the index.
  info                Displays runtime info about the bazel server.
  license             Prints the license of this software.
  mobile-install      Installs targets to mobile devices.
  print_action        Prints the command line args for compiling a file.
  query               Executes a dependency graph query.
  run                 Runs the specified target.
  shutdown            Stops the bazel server.
  sync                Syncs all repositories specified in the workspace file
  test                Builds and runs the specified test targets.
  version             Prints version information for bazel.

Getting more help:
  bazel help <command>
                   Prints help and options for <command>.
  bazel help startup_options
                   Options for the JVM hosting bazel.
  bazel help target-syntax
                   Explains the syntax for specifying targets.
  bazel help info-keys
                   Displays a list of keys used by the info command.
```

# TensorFlowをクローンする
　ここは特に言うことありません。[Github](https://github.com/tensorflow/tensorflow)からクローンしましょう。

#ビルド
　それでは、`tensorflow/tensorflow/lite/c/`のReadmeに書いてある通りビルドします。といっても、このままでは足りないのでエラーごとに解決法を書いていきます。(ユーザー名は`_`で隠してます。)

## その1（git）

```console
 - D:/program/git/tensolflow/WORKSPACE:37:1
ERROR: An error occurred during the fetch of repository 'io_bazel_rules_docker':
   Traceback (most recent call last):
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 177
                _clone_or_update(ctx)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
                git_repo(ctx, directory)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, in git_repo
                _update(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 101, in _update
                init(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 115, in init
                _error(ctx.name, cl, st.stderr)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 181, in _error
                fail(<1 more arguments>)
error running 'git init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker' while working with @io_bazel_rules_docker:
java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("git" init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker): ??????????????????
 (error: 2)
ERROR: no such package '@io_bazel_rules_docker//repositories': Traceback (most recent call last):
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 177
                _clone_or_update(ctx)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
                git_repo(ctx, directory)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, in git_repo
                _update(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 101, in _update
                init(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 115, in init
                _error(ctx.name, cl, st.stderr)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 181, in _error
                fail(<1 more arguments>)
error running 'git init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker' while working with @io_bazel_rules_docker:
java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("git" init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker): ??????????????????
 (error: 2)
ERROR: no such package '@io_bazel_rules_docker//repositories': Traceback (most recent call last):
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 177
                _clone_or_update(ctx)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
                git_repo(ctx, directory)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 91, in git_repo
                _update(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 101, in _update
                init(ctx, git_repo)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 115, in init
                _error(ctx.name, cl, st.stderr)
        File "C:/users/_/_bazel__/zpebvpgv/external/bazel_tools/tools/build_defs/repo/git_worker.bzl", line 181, in _error
                fail(<1 more arguments>)
error running 'git init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker' while working with @io_bazel_rules_docker:
java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("git" init C:/users/_/_bazel__/zpebvpgv/external/io_bazel_rules_docker): ??????????????????
```

###原因
　MSYS2を導入していない。または、MSYS2でgit等を使えるようにしていない。

###解決法
　[以下のページ](https://www.msys2.org/)からMSYS2を導入する。導入の際、セキュリティソフトに引っかかる場合があるので注意。
　インストールをしたら、MSYSを起動し、以下のコマンドでアップデートをする。

```sh
pacman -Su
```

　そしたら、落とせと言われるので×ボタンで落とし、また起動する。そして、以下のコマンドを打ちgit等を使えるようにする。

```sh
pacman -S zip unzip patch diffutils git
```

　そして、コマンドプロンプトからMSYS2のコマンドを使えるようにするため、`C:\msys64\usr\bin`までパスを通す。

##その2（Python was not found）

```console
ERROR: An error occurred during the fetch of repository 'local_config_python':
   Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
Internal error thrown during build. Printing stack trace: java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

INFO: Elapsed time: 36.164s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (11 packages loaded, 13 targets configured)
Internal error thrown during build. Printing stack trace: java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
```

###原因
　Microsoft StoreのPythonがない。Visual Studioとかはダメです。

###解決法
　[Microsoft StoreでPython](https://go.microsoft.com/fwlink?linkID=2082640)をインストールする。

##その3(unicodeescape)

```console
FAILED: Build did NOT complete successfully (11 packages loaded, 13 targets configured)
Internal error thrown during build. Printing stack trace: java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 210, in _create_local_python_repository
                _get_python_lib(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 130, in _get_python_lib
                execute(repository_ctx, <1 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Repository command failed
File "<string>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
```

###原因
　`C:\User`とかの`\U`がエスケープシーケンスとみなされる。

###解決法
　該当箇所を`\\U`や`/U`等に置き換える。今回の例では、`D:/program/git/tensolflow/third_party/py/python_configure.bzl`L208の`python_bin`という変数が原因なので、以下のように書き換えます。

```python
def _create_local_python_repository(repository_ctx):
    """Creates the repository containing files set up to build with Python."""

    # Resolve all labels before doing any real work. Resolving causes the
    # function to be restarted with all previous state being lost. This
    # can easily lead to a O(n^2) runtime in the number of labels.
    build_tpl = repository_ctx.path(Label("//third_party/py:BUILD.tpl"))

    python_bin = get_python_bin(repository_ctx).replace('\\', '/')
    _check_python_bin(repository_ctx, python_bin)
    python_lib = _get_python_lib(repository_ctx, python_bin)
```

##その4（No module）

```console
FAILED: Build did NOT complete successfully (11 packages loaded, 13 targets configured)
Internal error thrown during build. Printing stack trace: java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 213, in _create_local_python_repository
                _get_numpy_include(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 187, in _get_numpy_include
                execute(repository_ctx, <3 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Problem getting numpy include path.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Is numpy installed?, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
java.lang.IllegalStateException: //tensorflow/lite/c:tensorflowlite_c BuildConfigurationValue.Key[b1726b611bdc9a8863c0c9b5691f287791485d5c661e61bcfe9aef1d5e783a56] false -> ErrorInfo{exception=com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace: Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 263
                _create_local_python_repository(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 213, in _create_local_python_repository
                _get_numpy_include(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/py/python_configure.bzl", line 187, in _get_numpy_include
                execute(repository_ctx, <3 more arguments>)
        File "D:/program/git/tensolflow/third_party/remote_config/common.bzl", line 208, in execute
                fail(<1 more arguments>)
Problem getting numpy include path.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Is numpy installed?, rootCauses={REPOSITORY_DIRECTORY:@local_config_python}, cycles=[], isCatastrophic=false, rootCauseOfException=REPOSITORY_DIRECTORY:@local_config_python, isDirectlyTransient=false, isTransitivelyTransient=true}
        at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.assertSaneAnalysisError(SkyframeBuildView.java:760)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.processErrors(SkyframeBuildView.java:612)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:451)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:404)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:213)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:144)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:288)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:94)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:564)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:208)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:603)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:659)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
FAILED: Build did NOT complete successfully (11 packages loaded, 13 targets configured)
```

###原因
　Microsoft Storeのpythonに該当のパッケージがないのが原因です。

###解決法
　pipでインストールすればいいのですが、ほかの環境があるとそちらが優先されることが多いため、直接インストールされているところまで行ってpipするのが安全です。なお、私の場合は`C:\Users\_\AppData\Local\Microsoft\WindowsApps\`にありました。

##その5(python path)

```console
ERROR: An error occurred during the fetch of repository 'local_config_git':
   Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 54
                repository_ctx.execute(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 55, in repository_ctx.execute
                _get_python_bin(repository_ctx)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 27, in _get_python_bin
                _fail(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 14, in _fail
                fail(<1 more arguments>)
Git Configuration Error: Cannot find python in PATH, please make sure python is installed and add its directory in PATH, or --define PYTHON_BIN_PATH='/something/else'.
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Bazel;C:\msys64\usr\bin;C:\Users\_\AppData\Local\Microsoft\WindowsApps;C:\Users\_\AppData\Local\Programs\Microsoft VS Code\bin;D:\BrainWave\Graphviz\bin;C:\Program Files (x86)\FAHClient;C:\Users\_\.dotnet\tools
INFO: Call stack for the definition of repository 'com_google_absl' which is a tf_http_archive (rule definition at D:/program/git/tensolflow/third_party/repo.bzl:134:19):
 - <builtin>
 - D:/program/git/tensolflow/tensorflow/workspace.bzl:188:5
 - D:/program/git/tensolflow/WORKSPACE:19:1
ERROR: D:/program/git/tensolflow/tensorflow/core/util/BUILD:349:1: //tensorflow/core/util:version_info_gen depends on @local_config_git//:gen/spec.json in repository @local_config_git which failed to fetch. no such package '@local_config_git//': Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 54
                repository_ctx.execute(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 55, in repository_ctx.execute
                _get_python_bin(repository_ctx)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 27, in _get_python_bin
                _fail(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 14, in _fail
                fail(<1 more arguments>)
Git Configuration Error: Cannot find python in PATH, please make sure python is installed and add its directory in PATH, or --define PYTHON_BIN_PATH='/something/else'.
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Bazel;C:\msys64\usr\bin;C:\Users\_\AppData\Local\Microsoft\WindowsApps;C:\Users\_\AppData\Local\Programs\Microsoft VS Code\bin;D:\BrainWave\Graphviz\bin;C:\Program Files (x86)\FAHClient;C:\Users\_\.dotnet\tools
ERROR: D:/program/git/tensolflow/tensorflow/core/util/BUILD:349:1: //tensorflow/core/util:version_info_gen depends on @local_config_git//:gen/head in repository @local_config_git which failed to fetch. no such package '@local_config_git//': Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 54
                repository_ctx.execute(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 55, in repository_ctx.execute
                _get_python_bin(repository_ctx)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 27, in _get_python_bin
                _fail(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 14, in _fail
                fail(<1 more arguments>)
Git Configuration Error: Cannot find python in PATH, please make sure python is installed and add its directory in PATH, or --define PYTHON_BIN_PATH='/something/else'.
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Bazel;C:\msys64\usr\bin;C:\Users\_\AppData\Local\Microsoft\WindowsApps;C:\Users\_\AppData\Local\Programs\Microsoft VS Code\bin;D:\BrainWave\Graphviz\bin;C:\Program Files (x86)\FAHClient;C:\Users\_\.dotnet\tools
ERROR: D:/program/git/tensolflow/tensorflow/core/util/BUILD:349:1: //tensorflow/core/util:version_info_gen depends on @local_config_git//:gen/branch_ref in repository @local_config_git which failed to fetch. no such package '@local_config_git//': Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 54
                repository_ctx.execute(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 55, in repository_ctx.execute
                _get_python_bin(repository_ctx)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 27, in _get_python_bin
                _fail(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 14, in _fail
                fail(<1 more arguments>)
Git Configuration Error: Cannot find python in PATH, please make sure python is installed and add its directory in PATH, or --define PYTHON_BIN_PATH='/something/else'.
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Bazel;C:\msys64\usr\bin;C:\Users\_\AppData\Local\Microsoft\WindowsApps;C:\Users\_\AppData\Local\Programs\Microsoft VS Code\bin;D:\BrainWave\Graphviz\bin;C:\Program Files (x86)\FAHClient;C:\Users\_\.dotnet\tools
ERROR: Analysis of target '//tensorflow/lite/c:tensorflowlite_c' failed; build aborted: no such package '@local_config_git//': Traceback (most recent call last):
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 54
                repository_ctx.execute(<2 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 55, in repository_ctx.execute
                _get_python_bin(repository_ctx)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 27, in _get_python_bin
                _fail(<1 more arguments>)
        File "D:/program/git/tensolflow/third_party/git/git_configure.bzl", line 14, in _fail
                fail(<1 more arguments>)
Git Configuration Error: Cannot find python in PATH, please make sure python is installed and add its directory in PATH, or --define PYTHON_BIN_PATH='/something/else'.
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\dotnet\;C:\Bazel;C:\msys64\usr\bin;C:\Users\_\AppData\Local\Microsoft\WindowsApps;C:\Users\_\AppData\Local\Programs\Microsoft VS Code\bin;D:\BrainWave\Graphviz\bin;C:\Program Files (x86)\FAHClient;C:\Users\_\.dotnet\tools
INFO: Elapsed time: 8.178s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (37 packages loaded, 261 targets configured)
    Fetching @farmhash_archive; fetching
    Fetching ...rchive; Extracting C:/users/_/_bazel__/zpebvpgv/external/farmhash_archive/816a4ae622e964763ca0\
862d9dbd19324a1eaf45.tar.gz
```

###原因
　Microsoftのpythonへのパスである`PYTHON_BIN_PATH`が設定されていません。

###解決法
　環境変数で、`PYTHON_BIN_PATH`が設定します。

#さいごに
　私のであったエラーは以上です。ほんとはtensorflow liteと自分のものを分けないといけないけど、VCでリンクさせるのがなんかできなかったからapi.h、api.cに直接書いてしまった...