tensorflow: CPU Build Fails on OSX Sierra

I’m getting a cpu-only Bazel build failure on OSX. TensorFlow has already been .configure’d with default options.

Message below.

$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --verbose_failures
WARNING: /Users/kevin/projects/tensorflow/tensorflow/core/BUILD:1653:1: in includes attribute of cc_library rule //tensorflow/core:framework_headers_lib: '../../external/nsync/public' resolves to 'external/nsync/public' not below the relative path of its package 'tensorflow/core'. This will be an error in the future. Since this rule was created by the macro 'cc_header_only_library', the error might have been caused by the macro implementation in /Users/kevin/projects/tensorflow/tensorflow/tensorflow.bzl:913:30.
WARNING: /Users/kevin/projects/tensorflow/tensorflow/contrib/learn/BUILD:15:1: in py_library rule //tensorflow/contrib/learn:learn: target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:exporter': No longer supported. Switch to SavedModel immediately.
WARNING: /Users/kevin/projects/tensorflow/tensorflow/contrib/learn/BUILD:15:1: in py_library rule //tensorflow/contrib/learn:learn: target '//tensorflow/contrib/learn:learn' depends on deprecated target '//tensorflow/contrib/session_bundle:gc': No longer supported. Switch to SavedModel immediately.
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/external/nsync/BUILD:397:1: C++ compilation of rule '@nsync//:nsync_cpp' failed (Exit 1): cc_wrapper.sh failed: error executing command
  (cd /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/org_tensorflow && \
  exec env - \
    PATH=/anaconda/bin:/Users/kevin/bin:/usr/local/Cellar/coreutils/8.28/libexec/gnubin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/anaconda/bin/python \
    PYTHON_LIB_PATH=/anaconda/lib/python3.5/site-packages \
    TF_NEED_CUDA=0 \
    TF_NEED_OPENCL=0 \
    TMPDIR=/var/folders/g9/fdv74qn92qs7yw31tlj4q0lw0000gn/T/ \
  external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-march=native' -MD -MF bazel-out/local-py3-opt/bin/external/nsync/_objs/nsync_cpp/external/nsync/internal/time_internal.pic.d -fPIC -iquote external/nsync -iquote bazel-out/local-py3-opt/genfiles/external/nsync -iquote external/bazel_tools -iquote bazel-out/local-py3-opt/genfiles/external/bazel_tools -isystem external/nsync/public -isystem bazel-out/local-py3-opt/genfiles/external/nsync/public -isystem external/bazel_tools/tools/cpp/gcc3 -x c++ '-std=c++11' -DNSYNC_ATOMIC_CPP11 -DNSYNC_USE_CPP11_TIMEPOINT -I./external/nsync//platform/c++11 -I./external/nsync//platform/gcc -I./external/nsync//platform/x86_64 -I./external/nsync//public -I./external/nsync//internal -I./external/nsync//platform/posix '-D_POSIX_C_SOURCE=200809L' -pthread -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/nsync/internal/time_internal.c -o bazel-out/local-py3-opt/bin/external/nsync/_objs/nsync_cpp/external/nsync/internal/time_internal.pic.o).
In file included from external/nsync/internal/time_internal.c:16:
In file included from ./external/nsync//platform/c++11/platform.h:29:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/mutex:189:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__mutex_base:17:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:156:1: error: unknown type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port();
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:300:1: error: unknown type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port() {
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:301:12: error: use of undeclared identifier 'pthread_mach_thread_np'
    return pthread_mach_thread_np(pthread_self());
           ^
3 errors generated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 0.830s, Critical Path: 0.26s

TensorFlow commit: e9d5ee1ebffba25cef65f1f354b9e4ca9bcea10c

Mac OSX Sierra 10.12.6 (16G29) Command Line Tools:

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 9.0.0.0.1.1504363082
volume: /
location: /
install-time: 1505966986
groups: com.apple.FindSystemFiles.pkg-group

Environment Capture Script:

$ cat tf_env.txt

== cat /etc/issue ===============================================
Darwin MacBook-Pro.localdomain 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Mac OS X 10.12.6

== are we in docker =============================================
No

== compiler =====================================================
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

== uname -a =====================================================
Darwin MacBook-Pro.localdomain 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

== check pips ===================================================
numpy (1.13.1)
numpydoc (0.7.0)
protobuf (3.4.0)
tensorflow (1.3.0)
tensorflow-tensorboard (0.1.6)

== check for virtualenv =========================================
False

== tensorflow import ============================================
tf.VERSION = 1.3.0
tf.GIT_VERSION = v1.3.0-rc2-20-g0787eee
tf.COMPILER_VERSION = v1.3.0-rc2-20-g0787eee
Sanity check: array([1], dtype=int32)
Traceback (most recent call last):
  File "/Users/kevin/projects/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 48, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/kevin/projects/tensorflow/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/Users/kevin/projects/tensorflow/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Users/kevin/projects/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 59, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Users/kevin/projects/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 48, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

== env ==========================================================
LD_LIBRARY_PATH is unset
DYLD_LIBRARY_PATH is unset

== nvidia-smi ===================================================
tools/tf_env_collect.sh: line 105: nvidia-smi: command not found

== cuda libs  ===================================================

Bazel Information:

$ bazel info
bazel-bin: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/org_tensorflow/bazel-out/local-py3-opt/bin
bazel-genfiles: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/org_tensorflow/bazel-out/local-py3-opt/genfiles
bazel-testlogs: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/org_tensorflow/bazel-out/local-py3-opt/testlogs
character-encoding: file.encoding = ISO-8859-1, defaultCharset = ISO-8859-1
command_log: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/command.log
committed-heap-size: 1180MB
execution_root: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/org_tensorflow
gc-count: 15
gc-time: 1146ms
install_base: /var/tmp/_bazel_kevin/install/ed43083c802b447b0d9313e2450af83f
java-home: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
java-runtime: Java(TM) SE Runtime Environment (build 1.8.0_144-b01) by Oracle Corporation
java-vm: Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode) by Oracle Corporation
max-heap-size: 3817MB
message_log: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/message.log
output_base: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8
output_path: /private/var/tmp/_bazel_kevin/1cea9193b5038a270f5e322e515767d8/execroot/tensorflow/bazel-out
package_path: %workspace%
release: release 0.5.4-homebrew
server_pid: 37949
used-heap-size: 394MB
workspace: /Users/kevin/projects/tensorflow

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 47 (7 by maintainers)

Most upvoted comments

I started getting this error yesterday after upgrading XCODE for a different project I’m working on.

temporary hack fix in __threading_support

#ifndef _MACH_PORT_T
#define _MACH_PORT_T
#include <sys/_types.h> /* __darwin_mach_port_t */
typedef __darwin_mach_port_t mach_port_t;
mach_port_t pthread_mach_thread_np(pthread_t);
#endif /* _MACH_PORT_T */

Obviously not a long term solution, however it unblocks me today.

Built Successfully with fix:

Inserting following codes

#ifndef _MACH_PORT_T
#define _MACH_PORT_T
#include <sys/_types.h> /* __darwin_mach_port_t */
typedef __darwin_mach_port_t mach_port_t;
#include <pthread.h>
mach_port_t pthread_mach_thread_np(pthread_t);
#endif /* _MACH_PORT_T */

into file:

/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support

I tried to add

#ifndef _MACH_PORT_T
#define _MACH_PORT_T
#include <sys/_types.h> /* __darwin_mach_port_t */
typedef __darwin_mach_port_t mach_port_t;
#include <pthread.h>
mach_port_t pthread_mach_thread_np(pthread_t);
#endif /* _MACH_PORT_T */

to the top of /Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support but still got

ERROR: /private/var/tmp/_bazel_zhiyzuo/c6ab565d8235ea2aeef2da37c98dc58b/external/nsync/BUILD:397:1: C++ compilation of rule '@nsync//:nsync_cpp' failed (Exit 1).
In file included from external/nsync/internal/note.c:16:
In file included from ./external/nsync//platform/c++11/platform.h:29:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/mutex:189:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__mutex_base:17:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:15:36: error: unknown type name 'pthread_t'
mach_port_t pthread_mach_thread_np(pthread_t);
                                   ^
1 error generated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build

Any advice? -Also a CPU only config.

Got the same error building TF for Java from source on Sierra 10.12.6. ERROR: /private/var/tmp/_bazel_florin/5b9ecfceebaed4e3d76cf68084343c78/external/nsync/BUILD:397:1: C++ compilation of rule '@nsync//:nsync_cpp' failed (Exit 1). In file included from external/nsync/internal/wait.c:16: In file included from ./external/nsync//platform/c++11/platform.h:29: In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/mutex:189: In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__mutex_base:17: /Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:156:1: error: unknown type name 'mach_port_t' mach_port_t __libcpp_thread_get_port(); ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:300:1: error: unknown type name 'mach_port_t' mach_port_t __libcpp_thread_get_port() { ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/__threading_support:301:12: error: use of undeclared identifier 'pthread_mach_thread_np' return pthread_mach_thread_np(pthread_self()); ^