Windows下Bazel编译TFLite提示Python不可执行的问题求助
Windows下Bazel编译TensorFlow Lite时Python路径不可执行错误
环境与操作流程
- 系统:Windows
- 目标:编译C++版本TensorFlow Lite(TFLite),基于r2.12分支
- 已完成操作:
- 安装所有依赖并添加至系统PATH
- 克隆TensorFlow仓库并切换到r2.12分支
- 运行
python ./configure.py选择默认配置(同意覆盖eigen强内联),系统识别到Python路径为C:\Users\Asus\AppData\Local\Programs\Python\Python311\python.exe
错误详情
执行编译命令 bazel build -c opt //tensorflow/lite:tensorflowlite 时,出现核心错误:
ERROR: Analysis of target '//tensorflow/lite:tensorflowlite' failed; build aborted: Configuration Error: --define PYTHON_BIN_PATH='C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe' is not executable. Is it the python binary?
完整错误日志如下:
Starting local Bazel server and connecting to it... INFO: Options provided by the client: Inherited 'common' options: --isatty=1 --terminal_columns=117 INFO: Reading rc options for 'build' from c:\users\asus\desktop\tensorflow\.bazelrc: Inherited 'common' options: --experimental_repo_remote_exec INFO: Options provided by the client: 'build' options: --python_path=C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe INFO: Reading rc options for 'build' from c:\users\asus\desktop\tensorflow\.bazelrc: 'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility INFO: Reading rc options for 'build' from c:\users\asus\desktop\tensorflow\.tf_configure.bazelrc: 'build' options: --action_env PYTHON_BIN_PATH=C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe --action_env PYTHON_LIB_PATH=C:/Users/Asus/AppData/Local/Programs/Python/Python311/Lib/site-packages --python_path=C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe --copt=/d2ReducedOptimizeHugeFunctions --host_copt=/d2ReducedOptimizeHugeFunctions --define=override_eigen_strong_inline=true INFO: Reading rc options for 'build' from c:\users\asus\desktop\tensorflow\.bazelrc: 'build' options: --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/ir,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_jitrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils INFO: Found applicable config definition build:short_logs in file c:\users\asus\desktop\tensorflow\.bazelrc: --output_filter=DONT_MATCH_ANYTHING INFO: Found applicable config definition build:v2 in file c:\users\asus\desktop\tensorflow\.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1 INFO: Found applicable config definition build:windows in file c:\users\asus\desktop\tensorflow\.bazelrc: --copt=/W0 --host_copt=/W0 --copt=/Zc:__cplusplus --host_copt=/Zc:__cplusplus --copt=/D_USE_MATH_DEFINES --host_copt=/D_USE_MATH_DEFINES --features=compiler_param_file --copt=/d2ReducedOptimizeHugeFunctions --host_copt=/d2ReducedOptimizeHugeFunctions --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 --config=monolithic --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN --copt=-DNOGDI --host_copt=-DNOGDI --copt=/Zc:preprocessor --host_copt=/Zc:preprocessor --linkopt=/DEBUG --host_linkopt=/DEBUG --linkopt=/OPT:REF --host_linkopt=/OPT:REF --linkopt=/OPT:ICF --host_linkopt=/OPT:ICF --verbose_failures --features=compiler_param_file --distinct_host_configuration=false INFO: Found applicable config definition build:monolithic in file c:\users\asus\desktop\tensorflow\.bazelrc: --define framework_shared_object=false --define tsl_protobuf_header_only=false --experimental_link_static_libraries_once=false INFO: Repository local_config_python instantiated at: C:/users/asus/desktop/tensorflow/WORKSPACE:15:14: in <toplevel> C:/users/asus/desktop/tensorflow/tensorflow/workspace2.bzl:957:19: in workspace C:/users/asus/desktop/tensorflow/tensorflow/workspace2.bzl:104:21: in _tf_toolchains Repository rule python_configure defined at: C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl:298:35: in <toplevel> ERROR: An error occurred during the fetch of repository 'local_config_python': Traceback (most recent call last): File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 271, column 40, in _python_autoconf_impl _create_local_python_repository(repository_ctx) File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 212, column 22, in _create_local_python_repository _check_python_bin(repository_ctx, python_bin) File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 145, column 25, in _check_python_bin auto_config_fail("--define %s='%s' is not executable. Is it the python binary?" % ( File "C:/users/asus/desktop/tensorflow/third_party/remote_config/common.bzl", line 12, column 9, in auto_config_fail fail("%sConfiguration Error:%s %s " % (red, no_color, msg)) Error in fail: Configuration Error: --define PYTHON_BIN_PATH='C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe' is not executable. Is it the python binary? ERROR: C:/users/asus/desktop/tensorflow/WORKSPACE:15:14: fetching python_configure rule //external:local_config_python: Traceback (most recent call last): File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 271, column 40, in _python_autoconf_impl _create_local_python_repository(repository_ctx) File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 212, column 22, in _create_local_python_repository _check_python_bin(repository_ctx, python_bin) File "C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl", line 145, column 25, in _check_python_bin auto_config_fail("--define %s='%s' is not executable. Is it the python binary?" % ( File "C:/users/asus/desktop/tensorflow/third_party/remote_config/common.bzl", line 12, column 9, in auto_config_fail fail("%sConfiguration Error:%s %s " % (red, no_color, msg)) Error in fail: Configuration Error: --define PYTHON_BIN_PATH='C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe' is not executable. Is it the python binary? INFO: Repository local_execution_config_python instantiated at: C:/users/asus/desktop/tensorflow/WORKSPACE:15:14: in <toplevel> C:/users/asus/desktop/tensorflow/tensorflow/workspace2.bzl:957:19: in workspace C:/users/asus/desktop/tensorflow/tensorflow/workspace2.bzl:94:27: in _tf_toolchains C:/users/asus/desktop/tensorflow/tensorflow/tools/toolchains/remote_config/configs.bzl:6:28: in initialize_rbe_configs C:/users/asus/desktop/tensorflow/tensorflow/tools/toolchains/remote_config/rbe_config.bzl:158:27: in _tensorflow_local_config Repository rule local_python_configure defined at: C:/users/asus/desktop/tensorflow/third_party/py/python_configure.bzl:279:41: in <toplevel> INFO: Repository go_sdk instantiated at: C:/users/asus/desktop/tensorflow/WORKSPACE:23:14: in <toplevel> C:/users/asus/desktop/tensorflow/tensorflow/workspace0.bzl:134:20: in workspace C:/users/asus/_bazel_asus/ddsftcyc/external/com_github_grpc_grpc/bazel/grpc_extra_deps.bzl:36:27: in grpc_extra_deps C:/users/asus/_bazel_asus/ddsftcyc/external/io_bazel_rules_go/go/private/sdk.bzl:431:28: in go_register_toolchains C:/users/asus/_bazel_asus/ddsftcyc/external/io_bazel_rules_go/go/private/sdk.bzl:130:21: in go_download_sdk Repository rule _go_download_sdk defined at: C:/users/asus/_bazel_asus/ddsftcyc/external/io_bazel_rules_go/go/private/sdk.bzl:117:35: in <toplevel> ERROR: Analysis of target '//tensorflow/lite:tensorflowlite' failed; build aborted: Configuration Error: --define PYTHON_BIN_PATH='C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe' is not executable. Is it the python binary? INFO: Elapsed time: 224.163s INFO: 0 processes. FAILED: Build did NOT complete successfully (32 packages loaded, 15 targets configured)
已尝试的无效方案
- 验证Python路径:直接在CMD执行
C:/Users/Asus/AppData/Local/Programs/Python/Python311/python.exe可正常启动Python - 卸载并重新安装Python,重新配置系统PATH
- 使用源码压缩包替代Git克隆的仓库
- 修改TensorFlow第三方py目录下的配置文件
疑问
该错误的根本原因是什么?如何解决以完成Windows环境下TFLite的编译?
内容的提问来源于stack exchange,提问作者Turgut
相关产品推荐
相关产品推荐

