16

I am running TensorFlow on Ubuntu 15.10. When I enter pip show tensorflow, I see that TF has been installed properly.

However, when I write import tensorflow as tf, I get the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow import contrib
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/__init__.py", line 23, in <module>
    from tensorflow.contrib import layers
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/__init__.py", line 68, in <module>
    from tensorflow.contrib.layers.python.layers import *
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/__init__.py", line 22, in <module>
    from tensorflow.contrib.layers.python.layers.initializers import *
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/initializers.py", line 24, in <module>
    from tensorflow.python.ops import random_ops
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/random_ops.py", line 23, in <module>
    from tensorflow.python.framework import ops
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 39, in <module>
    from tensorflow.python.framework import versions
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/versions.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/me/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/home/me/anaconda2/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.7.5: cannot open shared object file: No such file or directory

For what it's worth, I have followed the instructions here and set my LD_LIBRARY_PATH and CUDA_HOME environment variables.

Any advice?

EDIT:

I have installed CUDA 7.5 and added these to my .profile file:

export LD_LIBRARY_PATH="/usr/local/cuda-7.5/lib64"
export CUDA_HOME=/usr/local/cuda-7.5

However, I continue to see the same error message.

EDIT:

I see the following output when I run ldd /usr/local/cuda-7.5/lib64/libcudart.so.7.5:

linux-vdso.so.1 =>  (0x00007ffdac7ea000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc27a281000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc27a07d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc279e5e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc279c56000)
/lib64/ld-linux-x86-64.so.2 (0x00005604f5406000)

EDIT:

If it is relevant, I use GeForce GT640.

EDIT:

I followed @tommus' advice and called source ~/.profile before running TensorFlow, and now it works like a charm.

Thanks to everyone who tried to help me in the comments -- this is my first experience with any kind of Linux distribution, and I am really very appreciative of all the patient assistance I have received so far :-) You guys are absolutely awesome!

M.Y. Babt
  • 2,733
  • 7
  • 27
  • 49
  • 2
    tensorflow is looking for CUDA 7.5 in this case. Did you install CUDA 7.5 or CUDA 7.0? What path exactly did you set your `LD_LIBRARY_PATH` to? Is there a libcudart.so.7.5 on that path? – Robert Crovella Mar 22 '16 at 15:57
  • Hi! I installed CUDA 7.0, and I added this to my .profile file: `export LD_LIBRARY_PATH="/home/me/cuda/targets/ppc64le-linux/lib"` – M.Y. Babt Mar 22 '16 at 16:01
  • Try installing CUDA 7.5 instead. – Robert Crovella Mar 22 '16 at 16:04
  • @RobertCrovella Thanks, I will give it a shot. I will post again if I encounter any more trouble :-) – M.Y. Babt Mar 22 '16 at 16:06
  • @RobertCrovella What command should I write to find out the installation folder for CUDA 7.5? – M.Y. Babt Mar 22 '16 at 16:26
  • It should be evident from the install process. What process did you use to install it? (for example did you follow the linux installation guide ?) Are you working on a Power8 platform (ppc64le) ? The default install path should be `/usr/local/cuda` but it doesn't appear that you are using default. If you are installing CUDA to your local directory (`/home/me/...`), do you have an appropriate GPU and driver installed? The linux `find` command should be able to find any file, something like `find / -name libcudart.so.7.5`, but this may be a bit cluttered if you are not a root user. – Robert Crovella Mar 22 '16 at 16:34
  • @RobertCrovella I have updated my post. I installed CUDA 7.5 but still receive the same error message. – M.Y. Babt Mar 22 '16 at 16:58
  • What is the output of the `ldd /usr/local/cuda/lib64/libcudart.so.7.5`? What is the output of the `ls /usr/local/cuda/lib64/`? Of course paths may vary depends on where You have installed CUDA. You may also have to call: `sudo ldconfig` and try to rerun TensorFlow. – Tomasz Dzieniak Mar 22 '16 at 17:02
  • However, when I `cd` to the CUDA folder and write `ls`, `libcudart.so.75` is listed. – M.Y. Babt Mar 22 '16 at 17:05
  • Are You sure? If the file is there the command `ldd libcudart.so.7.5` must return a value. – Tomasz Dzieniak Mar 22 '16 at 17:07
  • @tommus I have updated my post with the output. – M.Y. Babt Mar 22 '16 at 17:08
  • Have You sourced `.profile` file after editing it? Call `source ~/.profile` and try to run TensorFlow. – Tomasz Dzieniak Mar 22 '16 at 17:23
  • @tommus That worked like a charm. Thank you so much! – M.Y. Babt Mar 22 '16 at 17:27
  • I've added an answer. If it works for You, please mark as valid. Glad I could help. – Tomasz Dzieniak Mar 22 '16 at 17:29

5 Answers5

9

After editing .profile file you either need to log out and log back in or run the following command:

source ~/.profile

The solution is persistent so there is no need to perform it ever again.

Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42
5

sudo nano /etc/ld.so.conf.d/nvidia.conf

Add this:

/usr/local/cuda-8.0/lib64

/usr/local/cuda-8.0/lib

run

sudo ldconfig

if it works well ,please tell me.

dreamer
  • 59
  • 1
  • 1
  • This worked well for me too, but please make sure you change the cuda version according to the version you have. for ex. I have 9.0 so the line i had to add was /usr/local/cuda-9.0/lib64. And if you don't know what is your cuda version please look here: https://stackoverflow.com/questions/9727688/how-to-get-the-cuda-version – Neeraj Komuravalli Mar 07 '18 at 21:16
  • This solved the problem of Pycharm remote interpreter. – Honghe.Wu Feb 21 '19 at 08:38
3

If you are using pip but other answers did not work for you, try this.

In my case this exact problem was solved by reinstalling tensorflow using:

pip install tensorflow

Pip must have messed up its dependencies or something when installing other packages after Tensorflow installation (I've run pip install -r requirements.txt afterwards for my own purposes --> that broke Tensorflow).

Morphing Coffee
  • 815
  • 1
  • 10
  • 20
0

You maybe need to update your cuDNN version as Tensorflow 1.3 doesn't work with cuDNN 5.1 or earlier. Download cuDNN 6.0 or upper and install to fix the issue

Asad
  • 2,782
  • 2
  • 16
  • 17
0

I had same error. I have to have Cuda 8.0 and CuDNN 5.1 for running some experiments!!

SOLUTION: Run python with Sudo Python

python
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow
Traceback (most recent call last):
File "", line 1, in 
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/init.py", line 22, in 
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/init.py", line 49, in 
from tensorflow.python import pywrap_tensorflow
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in 
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in 
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in 
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/ujjval/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

Failed to load the native TensorFlow runtime.

L_J
  • 2,351
  • 10
  • 23
  • 28