Issue 1:
Hi! Tensorflow is not properlly installed.

Here's the output of: python -c "import tensorflow; print(tensorflow.version)"

dyld: warning, LC_RPATH $ORIGIN/../../_solib_darwin/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Slib in /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so being ignored in restricted program because it is a relative path

dyld: warning, LC_RPATH ../local_config_cuda/cuda/lib in /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so being ignored in restricted program because it is a relative path

dyld: warning, LC_RPATH ../local_config_cuda/cuda/extras/CUPTI/lib in /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so being ignored in restricted program because it is a relative path

Traceback (most recent call last):

File "", line 1, in

File "/Library/Python/2.7/site-packages/tensorflow/init.py", line 24, in

from tensorflow.python import *

File "/Library/Python/2.7/site-packages/tensorflow/python/init.py", line 60, in

raise ImportError(msg)

ImportError: Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/tensorflow/python/init.py", line 49, in

from tensorflow.python import pywrap_tensorflow

File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in

_pywrap_tensorflow = swig_import_helper()

File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper

_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

ImportError: dlopen(/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib

Referenced from: /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so

Reason: image not found

OS: OSX 10.11.6

Tensorflow pip version: tensorflow-gpu==0.12.1

My "cuda" libs under /usr/local/cuda/lib/*

/usr/local/cuda/lib/libcublas.8.0.dylib	/usr/local/cuda/lib/libcusparse.8.0.dylib	/usr/local/cuda/lib/libnppim.8.0.dylib

/usr/local/cuda/lib/libcublas.dylib	/usr/local/cuda/lib/libcusparse.dylib	/usr/local/cuda/lib/libnppim.dylib

/usr/local/cuda/lib/libcublas_device.a	/usr/local/cuda/lib/libcusparse_static.a	/usr/local/cuda/lib/libnppim_static.a

/usr/local/cuda/lib/libcublas_static.a	/usr/local/cuda/lib/libnppc.8.0.dylib	/usr/local/cuda/lib/libnppist.8.0.dylib

/usr/local/cuda/lib/libcuda.dylib	/usr/local/cuda/lib/libnppc.dylib	/usr/local/cuda/lib/libnppist.dylib

/usr/local/cuda/lib/libcudadevrt.a	/usr/local/cuda/lib/libnppc_static.a	/usr/local/cuda/lib/libnppist_static.a

/usr/local/cuda/lib/libcudart.8.0.dylib	/usr/local/cuda/lib/libnppi.8.0.dylib	/usr/local/cuda/lib/libnppisu.8.0.dylib

/usr/local/cuda/lib/libcudart.dylib	/usr/local/cuda/lib/libnppi.dylib	/usr/local/cuda/lib/libnppisu.dylib

/usr/local/cuda/lib/libcudart_static.a	/usr/local/cuda/lib/libnppi_static.a	/usr/local/cuda/lib/libnppisu_static.a

/usr/local/cuda/lib/libcudnn.5.dylib	/usr/local/cuda/lib/libnppial.8.0.dylib	/usr/local/cuda/lib/libnppitc.8.0.dylib

/usr/local/cuda/lib/libcudnn.dylib	/usr/local/cuda/lib/libnppial.dylib	/usr/local/cuda/lib/libnppitc.dylib

/usr/local/cuda/lib/libcudnn_static.a	/usr/local/cuda/lib/libnppial_static.a	/usr/local/cuda/lib/libnppitc_static.a

/usr/local/cuda/lib/libcufft.8.0.dylib	/usr/local/cuda/lib/libnppicc.8.0.dylib	/usr/local/cuda/lib/libnpps.8.0.dylib

/usr/local/cuda/lib/libcufft.dylib	/usr/local/cuda/lib/libnppicc.dylib	/usr/local/cuda/lib/libnpps.dylib

/usr/local/cuda/lib/libcufft_static.a	/usr/local/cuda/lib/libnppicc_static.a	/usr/local/cuda/lib/libnpps_static.a

/usr/local/cuda/lib/libcufftw.8.0.dylib	/usr/local/cuda/lib/libnppicom.8.0.dylib	/usr/local/cuda/lib/libnvToolsExt.1.dylib

/usr/local/cuda/lib/libcufftw.dylib	/usr/local/cuda/lib/libnppicom.dylib	/usr/local/cuda/lib/libnvToolsExt.dylib

/usr/local/cuda/lib/libcufftw_static.a	/usr/local/cuda/lib/libnppicom_static.a	/usr/local/cuda/lib/libnvblas.8.0.dylib

/usr/local/cuda/lib/libcuinj.8.0.dylib	/usr/local/cuda/lib/libnppidei.8.0.dylib	/usr/local/cuda/lib/libnvblas.dylib

/usr/local/cuda/lib/libcuinj.dylib	/usr/local/cuda/lib/libnppidei.dylib	/usr/local/cuda/lib/libnvgraph.8.0.dylib

/usr/local/cuda/lib/libculibos.a	/usr/local/cuda/lib/libnppidei_static.a	/usr/local/cuda/lib/libnvgraph.dylib

/usr/local/cuda/lib/libcurand.8.0.dylib	/usr/local/cuda/lib/libnppif.8.0.dylib	/usr/local/cuda/lib/libnvgraph_static.a

/usr/local/cuda/lib/libcurand.dylib	/usr/local/cuda/lib/libnppif.dylib	/usr/local/cuda/lib/libnvrtc-builtins.8.0.dylib

/usr/local/cuda/lib/libcurand_static.a	/usr/local/cuda/lib/libnppif_static.a	/usr/local/cuda/lib/libnvrtc-builtins.dylib

/usr/local/cuda/lib/libcusolver.8.0.dylib	/usr/local/cuda/lib/libnppig.8.0.dylib	/usr/local/cuda/lib/libnvrtc.8.0.dylib

/usr/local/cuda/lib/libcusolver.dylib	/usr/local/cuda/lib/libnppig.dylib	/usr/local/cuda/lib/libnvrtc.dylib

/usr/local/cuda/lib/libcusolver_static.a	/usr/local/cuda/lib/libnppig_static.a

Issue 2:
Something related to linking seems to cause the build to fail on Mac OS 10.12.2 when building with CUDA.

Verbose build error is:

$ bazel build -c opt --config=cuda --verbose_failures //tensorflow/tools/pip_package:build_pip_package
INFO: Found 1 target...
ERROR: /Users/anton/tmp/tensorflow/tensorflow/contrib/ffmpeg/BUILD:66:1: Executing genrule //tensorflow/contrib/ffmpeg:decode_audio_op_py_pygenrule failed: bash failed: error executing command
(cd /private/var/tmp/_bazel_anton/d3361bfa15c75c42ab541f3d83e8eba4/execroot/tensorflow && \
exec env - \
PATH=/usr/local/cuda/bin:/Users/anton/.pyenv/shims:/Users/anton/.rbenv/shims:/Users/anton/.scalaenv/shims:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/anton/unix/bin:/usr/local/cuda/bin \
TMPDIR=/var/folders/4r/mq7ht1z11t72w5b5b6014zwm0000gn/T/ \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/contrib/ffmpeg/gen_decode_audio_op_py_py_wrappers_cc 1 > bazel-out/local_darwin-py3-opt/genfiles/tensorflow/contrib/ffmpeg/ops/gen_decode_audio_op_py.py'): com.google.devtools.build.lib.shell.AbnormalTerminationException: Process terminated by signal 6.
dyld: Library not loaded: @rpath/libcudart.8.0.dylib
Referenced from: /private/var/tmp/_bazel_anton/d3361bfa15c75c42ab541f3d83e8eba4/execroot/tensorflow/bazel-out/host/bin/tensorflow/contrib/ffmpeg/gen_decode_audio_op_py_py_wrappers_cc
Reason: image not found
/bin/bash: line 1: 72493 Abort trap: 6 bazel-out/host/bin/tensorflow/contrib/ffmpeg/gen_decode_audio_op_py_py_wrappers_cc 1 > bazel-out/local_darwin-py3-opt/genfiles/tensorflow/contrib/ffmpeg/ops/gen_decode_audio_op_py.py
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 2.707s, Critical Path: 0.32s

Related posts

It seems that Caffe had similar issues due to Apple dropping the LD_LIBRARY_PATH environment variable: BVLC/caffe#3227

Environment info

Operating System: Mac OS 10.12.2

Installed version of CUDA and cuDNN:

$ ls -l /usr/local/cuda/lib/libcud*
-rwxr-xr-x 1 root wheel 13504 Nov 3 19:39 /usr/local/cuda/lib/libcuda.dylib*
lrwxr-xr-x 1 root wheel 45 Nov 3 19:40 /usr/local/cuda/lib/libcudadevrt.a@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudadevrt.a
lrwxr-xr-x 1 root wheel 50 Nov 3 19:40 /usr/local/cuda/lib/libcudart.8.0.dylib@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudart.8.0.dylib
lrwxr-xr-x 1 root wheel 46 Nov 3 19:40 /usr/local/cuda/lib/libcudart.dylib@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudart.dylib
lrwxr-xr-x 1 root wheel 49 Nov 3 19:40 /usr/local/cuda/lib/libcudart_static.a@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudart_static.a
lrwxr-xr-x 1 root admin 47 Jan 8 16:48 /usr/local/cuda/lib/libcudnn.5.dylib@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.5.dylib
lrwxr-xr-x 1 root admin 45 Jan 8 16:48 /usr/local/cuda/lib/libcudnn.dylib@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.dylib
lrwxr-xr-x 1 root admin 48 Jan 8 16:48 /usr/local/cuda/lib/libcudnn_static.a@ -> /Developer/NVIDIA/CUDA-8.0/lib/libcudnn_static.a

Configuration command

Please specify the location of python. [Default is /Users/anton/.pyenv/shims/python]:
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] N
No Hadoop File System support will be enabled for TensorFlow
Error in sitecustomize; set PYTHONVERBOSE for traceback:
KeyError: 'PYTHONPATH'
Error in sitecustomize; set PYTHONVERBOSE for traceback:
KeyError: 'PYTHONPATH'
Error in sitecustomize; set PYTHONVERBOSE for traceback:
KeyError: 'PYTHONPATH'
Found possible Python library paths:
/Users/anton/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages
Please input the desired Python library path to use. Default is [/Users/anton/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages]

Using python library path: /Users/anton/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] Y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]:
Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify the Cudnn version you want to use. [Leave empty to use system default]:
Please specify the location where cuDNN library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
libcudnn.dylib resolves to libcudnn.dylib
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.5
Extracting Bazel installation...
............
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
.........
____Loading package: tensorflow/tools/git
____Loading package: tensorflow/contrib/opt
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 40,960 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 444,518 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 743,716 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 1,170,534 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 1,597,352 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 1,998,646 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 2,251,050 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 2,675,032 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 3,144,390 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 3,579,716 bytes
____Downloading http://bazel-mirror.storage.googleapis.com/github.com/google/protobuf/archive/008b5a228b37c054f46ba478ccafa5e855cb16db.tar.gz: 3,788,162 bytes
INFO: All external dependencies fetched successfully.
Configuration finished

Git revision

$ git rev-parse HEAD
ec7929b878926c39255254e9aea992f0bc65aa68

Bazel version

$ bazel version
Build label: 0.4.3-homebrew
Build target: bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 22 15:20:15 2016 (1482420015)
Build timestamp: 1482420015
Build timestamp as int: 1482420015

Update

I modified third_party/gpus/crosstool/CROSSTOOL.tpl the following lines

cxx_flag: "-std=c++11"
linker_flag: "-Wl,-no-as-needed"

in the toolchain section to:

cxx_flag: "-std=c++11"
linker_flag: "-Wl,-no-as-needed,-rpath,/usr/local/cuda/lib"

Now I get failures at:

ERROR: /Users/anton/tmp/tensorflow/tensorflow/python/BUILD:793:1: Executing genrule //tensorflow/python:control_flow_ops_pygenrule failed: bash failed: error executing command
(cd /private/var/tmp/_bazel_anton/d3361bfa15c75c42ab541f3d83e8eba4/execroot/tensorflow && \
exec env - \
PATH=/usr/local/cuda/bin:/Users/anton/.pyenv/shims:/Users/anton/.rbenv/shims:/Users/anton/.scalaenv/shims:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/anton/unix/bin:/usr/local/cuda/bin \
TMPDIR=/var/folders/4r/mq7ht1z11t72w5b5b6014zwm0000gn/T/ \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/python/gen_control_flow_ops_py_wrappers_cc @tensorflow/python/ops/hidden_ops.txt 1 > bazel-out/local_darwin-py3-opt/genfiles/tensorflow/python/ops/gen_control_flow_ops.py'): com.google.devtools.build.lib.shell.AbnormalTerminationException: Process terminated by signal 6.
dyld: Library not loaded: @rpath/libcudart.8.0.dylib
Referenced from: /private/var/tmp/_bazel_anton/d3361bfa15c75c42ab541f3d83e8eba4/execroot/tensorflow/bazel-out/host/bin/tensorflow/python/gen_control_flow_ops_py_wrappers_cc
Reason: image not found
/bin/bash: line 1: 45635 Abort trap: 6 bazel-out/host/bin/tensorflow/python/gen_control_flow_ops_py_wrappers_cc @tensorflow/python/ops/hidden_ops.txt 1 > bazel-out/local_darwin-py3-opt/genfiles/tensorflow/python/ops/gen_control_flow_ops.py
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 1683.463s, Critical Path: 1587.37s

I got a bit further but it seems that I need to modify the link options in more files.