在OSX上安装Tensorflow - clang: 错误:链接器命令以退出码1失败

3
我正在尝试从源代码安装适用于OSX(Mojave 10.14.3)的Tensorflow,并在终端中按照https://www.tensorflow.org/install/source上所述运行bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package时遇到以下错误:
Undefined symbols for architecture x86_64:
  "_PyModule_AddIntConstant", referenced from:
      _PyInit__api_implementation in api_implementation.o
  "_PyModule_Create2", referenced from:
      _PyInit__api_implementation in api_implementation.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.

根据stackoverflow上类似(但不完全相同)的帖子,这似乎与Xcode有关。我已经尝试重新安装Xcode命令行工具和更新Xcode本身,但无济于事。另外,我没有办法更改代码中的任何内容。感谢您的帮助!

1
创建了一个 Github 问题:https://github.com/tensorflow/tensorflow/issues/26589 - Geoffrey Irving
1个回答

0

这个问题已经在Bazel最新版本中得到解决。

修复此问题的代码如下:

#def system_specific_test_config(env): Deleted This Line
  """Add default test flags required for TF tests to bazelrc."""
def system_specific_config(env): #Added this Line
  """Add default build and test flags required for TF tests to bazelrc."""
  write_to_bazelrc('test --flaky_test_attempts=3')
  write_to_bazelrc('test --test_size_filters=small,medium')
  write_to_bazelrc(
@@ -1520,6 +1520,10 @@ def system_specific_test_config(env):
  elif is_macos():
    write_to_bazelrc('test --test_tag_filters=-gpu,-nomac,-no_mac')
    write_to_bazelrc('test --build_tag_filters=-gpu,-nomac,-no_mac')
    # TODO(pcloudy): Remove BAZEL_USE_CPP_ONLY_TOOLCHAIN after Bazel is upgraded
    # to 0.24.0.
    # For working around https://github.com/bazelbuild/bazel/issues/7607
    write_to_bazelrc('build --action_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1')
  elif is_linux():
    if env.get('TF_NEED_CUDA', None) == '1':
      write_to_bazelrc('test --test_tag_filters=-no_gpu')
@@ -1747,7 +1751,7 @@ def main():
    create_android_ndk_rule(environ_cp)
    create_android_sdk_rule(environ_cp)

  #system_specific_test_config(os.environ) #Deleted this Line
  system_specific_config(os.environ) #Added this Line

  if get_var(
      environ_cp, 'TF_CONFIGURE_APPLE_BAZEL_RULES',

更多信息,请参考链接1链接2


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接