6

I am trying to use tensorflow-gpu on my system. I have re-installed it many times, it gives the error give below. But when I use tensorflow-cpu it works fine. I have cuda 8.0 toolkit installed and cudnn 5.1.

  Traceback (most recent call last):
  File "finetune.py", line 17, in <module>
    import tensorflow as tf
  File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/saurabh/code/env/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
talonmies
  • 70,661
  • 34
  • 192
  • 269
talos1904
  • 952
  • 3
  • 9
  • 24
  • What do you get when running `echo $CUDA_HOME`? – Ali Apr 02 '17 at 00:25
  • Have you updated your PATH and LD_LIBRARY_PATH after installing cuda? – Kochoba Apr 02 '17 at 00:26
  • @Ali - there is no variable of that name. – talos1904 Apr 02 '17 at 00:58
  • @Kochoba - Yes I have updated them. **LD_LIBRARY_PATH - /home/saurabh/cuda/lib64** and **PATH - /usr/local/cuda-8.0/bin:/home/saurabh/code/env/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin** – talos1904 Apr 02 '17 at 00:58
  • run `export CUDA_HOME=/usr/local/cuda-8.0` then try again, is it resolved now? – Ali Apr 02 '17 at 01:02
  • Nope. Same error. – talos1904 Apr 02 '17 at 01:07
  • So I guess you also run `ldconfig` and `source ~/.bashrc` – Kochoba Apr 02 '17 at 01:22
  • @Ali - see this link, I have done all the things you suggested [link](https://drive.google.com/open?id=0B_AeHnM_eqofY1JrMGNVb1lVdFE) – talos1904 Apr 02 '17 at 01:25
  • @Kochoba - I ran **sudo ldconfig** and I got this in return [link](https://drive.google.com/open?id=0B_AeHnM_eqofVXNzNHpaSERhWVk). – talos1904 Apr 02 '17 at 01:32
  • Check this SO post for resolving this error http://stackoverflow.com/questions/11542255/ldconfig-error-is-not-a-symbolic-link then run `sudo ldconfig` again. You should get no output if it updates the libraries successfully – Kochoba Apr 02 '17 at 01:39
  • Also make sure for LD_LIBRARY_PATH you also include the directory for `libcudart.so.8.0` . For my system it is `/usr/local/cuda-8.0/lib64` – Kochoba Apr 02 '17 at 01:42
  • @Kochoba - I have done all things mentioned on the discussion and reinstalled my cuda toolkit and cudnn, tensorflow works with gpu now! Thanks! – talos1904 Apr 02 '17 at 03:55

3 Answers3

9

If changing your path variable does not work, running the following in your terminal is what usually solves this for me:

sudo ldconfig /usr/local/cuda/lib64

(sometimes cuda may need to be something like cuda-8.0, depending on your installation)

Michele Tonutti
  • 4,298
  • 1
  • 21
  • 22
5

The problem is that you don't have environment variable CUDA_HOME set. If you think you have CUDA installed, then you need to make sure that the above environment variable is set prob=perly and contains address of the CUDA installation directory where all share libraries are located.

export CUDA_HOME=/CUDA/installation/path
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64"
Ali
  • 1,605
  • 1
  • 13
  • 19
  • I have not read about CUDA_HOME variable in any documentation. But I know I have to change PATH and LD_LIBRARY_PATH (as mentioned in the comments above) which I have already done. Can you please send some me some link where CUDA_HOME variable is set? – talos1904 Apr 02 '17 at 01:05
  • I ran this command in my virtual env - **# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.** **export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl** But this is for Cuda 7.5, but still shows the same error but the last portion and below part **Failed to load the native TensorFlow runtime.** is gone. See this link and compare with the error in the question [link](https://drive.google.com/open?id=0B_AeHnM_eqofNW1GdFl0OFcxNVE) – talos1904 Apr 02 '17 at 01:17
  • Sorry, what exactly is happening? – Ali Apr 02 '17 at 01:19
  • I ran this command - **export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl**. It now give me this error [link](https://drive.google.com/file/d/0B_AeHnM_eqofNW1GdFl0OFcxNVE/view) – talos1904 Apr 02 '17 at 01:29
  • Looks like that this time TF is using CUDA 7.5 and again the corresponding env variables are not appropriately set. – Ali Apr 02 '17 at 01:57
1

sudo ldconfig /usr/local/cuda/lib64

Works for me.

Please refer this link for more information. https://github.com/tensorflow/tensorflow/issues/5343

Luna Kong
  • 3,065
  • 25
  • 20