首页 > 解决方案 > 如何在 OS X 11.6 (Big Sur) 上构建 Tensorflow 2.8 Wheel

问题描述

% pip --version
pip 21.2.4 from /Users/davidlaxer/anaconda3/envs/ai/lib/python3.8/site-packages/pip (python 3.8)

(ai) davidlaxer@x86_64-apple-darwin13 tensorflow % xcrun --show-sdk-build-version
20E214
(ai) davidlaxer@x86_64-apple-darwin13 tensorflow % xcrun --show-sdk-version    
11.3
(ai) davidlaxer@x86_64-apple-darwin13 tensorflow % xcrun --show-sdk-path   
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
(ai) davidlaxer@x86_64-apple-darwin13 tensorflow % xcrun --show-sdk-platform-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform

我能够构建 TensorFlow 2.8

% ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Sat Sep 25 18:38:59 PDT 2021 : === Preparing sources in dir: /var/folders/3n/56fpv14n4wj0c1l1sb106pzw0000gn/T/tmp.XXXXXXXXXX.trGVfZR1
~/tensorflow ~/tensorflow
~/tensorflow
~/tensorflow/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow ~/tensorflow
~/tensorflow
/var/folders/3n/56fpv14n4wj0c1l1sb106pzw0000gn/T/tmp.XXXXXXXXXX.trGVfZR1/tensorflow/include ~/tensorflow
~/tensorflow
Sat Sep 25 18:39:23 PDT 2021 : === Building wheel
warning: no files found matching 'README'
warning: no files found matching '*.pyd' under directory '*'
warning: no files found matching '*.pyi' under directory '*'
warning: no files found matching '*.pd' under directory '*'
warning: no files found matching '*.so.[0-9]' under directory '*'
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.csv' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*.proto' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow/include/third_party'
[WARNING] This wheel needs a higher macOS version than the version your Python interpreter is compiled against.  To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least 11_0 or recreate these files with lower MACOSX_DEPLOYMENT_TARGET:  
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.2.8.0.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.2.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/core/platform/_cpu_feature_guard.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tfe.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_quantize_training.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tfcompile.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_toco_api.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_mlir.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_parallel_device.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_py_exception_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tensorflow_internal.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_sanitizers.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/autograph/impl/testing/pybind_for_testing.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/saved_model/pywrap_saved_model.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_transform_graph.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_kernel_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_stat_summarizer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_tf_stack.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_tfprof.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_nest.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_util_port.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/fast_module_type.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_checkpoint_reader.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_tensor_float_32_execution.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_determinism.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_dtypes.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_op_def_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_info.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/fast_tensor_util.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_errors_test_helper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_python_memory_checker_helper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_op_gen.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_dispatcher.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_parameter_converter.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_op_def_util.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_proto_comparators.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/platform/_pywrap_tf2.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/platform/_pywrap_stacktrace_handler.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_optimizer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_cluster.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_item.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/core/_pywrap_bfloat16.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/core/_pywrap_py_func.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/io/_pywrap_record_io.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/io/_pywrap_file_io.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/profiler/internal/_pywrap_profiler.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/profiler/internal/_pywrap_traceme.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/data/experimental/service/_pywrap_server_lib.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/data/experimental/service/_pywrap_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_device_lib.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_tf_session.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_debug_events_writer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_events_writer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/optimize/_pywrap_tensorflow_lite_calibration_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/metrics_wrapper/_pywrap_tensorflow_lite_metrics_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/interpreter_wrapper/_pywrap_tensorflow_interpreter_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/analyzer_wrapper/_pywrap_analyzer_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/compiler/tf2tensorrt/_pywrap_py_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/compiler/tf2xla/ops/_xla_ops.so[WARNING] This wheel needs a higher macOS version than the version your Python interpreter is compiled against.  To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least 11_0 or recreate these files with lower MACOSX_DEPLOYMENT_TARGET:  
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.2.8.0.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.2.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.dylib
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/core/platform/_cpu_feature_guard.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tfe.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_quantize_training.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tfcompile.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_toco_api.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_mlir.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_parallel_device.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_py_exception_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_tensorflow_internal.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/_pywrap_sanitizers.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/autograph/impl/testing/pybind_for_testing.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/saved_model/pywrap_saved_model.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_transform_graph.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_kernel_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_stat_summarizer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_tf_stack.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_tfprof.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_nest.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_util_port.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/fast_module_type.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_checkpoint_reader.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_tensor_float_32_execution.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_determinism.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/util/_pywrap_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_dtypes.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_op_def_registry.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_info.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/fast_tensor_util.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_errors_test_helper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_python_memory_checker_helper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_op_gen.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_dispatcher.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_pywrap_python_api_parameter_converter.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_op_def_util.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/framework/_proto_comparators.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/platform/_pywrap_tf2.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/platform/_pywrap_stacktrace_handler.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_optimizer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_cluster.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/grappler/_pywrap_tf_item.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/core/_pywrap_bfloat16.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/core/_pywrap_py_func.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/io/_pywrap_record_io.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/lib/io/_pywrap_file_io.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/profiler/internal/_pywrap_profiler.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/profiler/internal/_pywrap_traceme.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/data/experimental/service/_pywrap_server_lib.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/data/experimental/service/_pywrap_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_device_lib.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_tf_session.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_debug_events_writer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/python/client/_pywrap_events_writer.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/optimize/_pywrap_tensorflow_lite_calibration_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/metrics_wrapper/_pywrap_tensorflow_lite_metrics_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/interpreter_wrapper/_pywrap_tensorflow_interpreter_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/lite/python/analyzer_wrapper/_pywrap_analyzer_wrapper.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/compiler/tf2tensorrt/_pywrap_py_utils.so
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/compiler/tf2xla/ops/_xla_ops.soSat Sep 25 18:39:53 PDT 2021 : === Output wheel file is in: /tmp/tensorflow_pkg
(ai) davidlaxer@x86_64-apple-darwin13 tensorflow % ls -l !$                    
ls -l /tmp/tensorflow_pkg
total 406912
-rw-r--r--  1 davidlaxer  wheel  208337877 Sep 25 18:39 tensorflow-2.8.0-cp38-cp38-macosx_11_0_x86_64.whl

但是,pip 无法安装轮子。

$ pip install /tmp/tensorflow_pkg/tensorflow-2.8.0-cp38-cp38-macosx_11_0_x86_64.whl 
ERROR: tensorflow-2.8.0-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.

为什么 bazel-bin 构建 build/bdist.macosx-10.9-x86_64/w 而不是 11.5?

[WARNING] This wheel needs a higher macOS version than the version your Python interpreter is compiled against.  To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least 11_0 or recreate these files with lower MACOSX_DEPLOYMENT_TARGET:  
build/bdist.macosx-10.9-x86_64/wheel/tensorflow/libtensorflow_framework.2.8.0.dylib

标签: pythontensorflowpippython-3.8python-wheel

解决方案


通过使用 SYSTEM_VERSION_COMPAT=0,我能够安装和导入 tensorflow 2.8(从 Big Sur - OS X 11.6 上的源代码构建):

 SYSTEM_VERSION_COMPAT=0 python -m pip install /tmp/tensorflow_pkg/tensorflow-2.8.0-cp38-cp38-macosx_11_0_x86_64.whl

不幸的是,它破坏了似乎需要 tensorflow 2.5.1 的 tensorflow_text。


推荐阅读