'Library not loaded: @rpath/libcudart.7.5.dylib' TensorFlow Error on Mac
This error message is displayed if you install the GPU-enabled Mac OS version of TensorFlow (available from release 0.10 onwards) on a machine that does not have CUDA installed.
To fix the error, install the CPU version for Python 2.7 or 3.x, as follows:
# Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py2-none-any.whl
$ sudo pip install --upgrade $TF_BINARY_URL
# Mac OS X, CPU only, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL
See tensorflow versions: https://www.tensorflow.org/versions/
To add to @mrry's answer, if you already have CUDA installed but you still get the error, it could be because the CUDA libraries are not on your path. Add the following to your ~/.bashrc or ~/.zshrc:
# export CUDA_HOME=/Developer/NVIDIA/CUDA-7.5 ## This is the default location on macOS
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"
export PATH="$CUDA_HOME/bin:$PATH"
Uncomment either of the CUDA_HOME
s or edit it so that it contains your CUDA install. If you do not know where it is installed, try:
find / -name "*libcudart*"
Certainly installing CUDA is essential, as is ensuring that all the paths are correct. I'm running:
- TensorFlow 0.12r0
- OSX 10.12.1
- python 2.7 from brew
- virtualenv to separate my python environments
- CUDA 8.0.55
- cudnn-8.0-osx-x64-v5.1
On my system I have also had further issues where it appears that the problem originates from the dynamic libraries internally referencing relative paths.
To discover the @rpath
being referenced from _pywrap_tensorflow.so
the following code is run:
otool -l /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so
which returned, amongst other things, the following:
Load command 15
cmd LC_RPATH
cmdsize 128
path $ORIGIN/../../_solib_darwin/_U@local_Uconfig_Ucuda_S_Scuda_Ccudart___Uexternal_Slocal_Uconfig_Ucuda_Scuda_Slib (offset 12)
Load command 16
cmd LC_RPATH
cmdsize 48
path ../local_config_cuda/cuda/lib (offset 12)
Load command 17
cmd LC_RPATH
cmdsize 56
path ../local_config_cuda/cuda/extras/CUPTI/lib (offset 12)
It can be seen that the dynamic library is attempting to find the CUDA libraries within my virtual environment where I installed TensorFlow with pip. It's not looking within my systems environment paths.
A hack around of a solution is to dynamically link the CUDA libraries from their /usr/local/cuda/lib
location into the site-packages where pip installed TensorFlow inside my virtual environment.
mkdir /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda
cd /Users/norman_h/.virtualenvs/env_name/lib/python2.7/site-packages/tensorflow/local_config_cuda
ln -s /usr/local/cuda .
Will need to re-link when pip upgrades TensorFlow from within the virtual environment.
I think this all goes back to the original compilation of TensorFlow that is done for the pip install and I have no idea how to submit a fix, or even if I am correct. Perhaps the original compilation of Tensorflow needs to be more dynamic and not static.
Best of luck!