44
votes

I'm having problems in importing tensorflow in python3:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory


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.

I am using Nvidia drivers version 381.09 beta, as version 375 has this bug: https://askubuntu.com/questions/896221/strange-artifacts-along-window-borders-after-waking-computer-from-sleep-mode?noredirect=1&lq=1

I have install CUDA 8.0 and cuDNN-v6.0:

rharish@rharish-GL552VW:~$ cd /usr/local
rharish@rharish-GL552VW:/usr/local$ ls
bin         cuda      etc    include  man   share
computecpp  cuda-8.0  games  lib      sbin  src

Also, libcusolver.so.8.0 exists in /usr/local/cuda/lib64/:

libcusolver.so.8.0 in 'ls' output

I have uninstalled and reinstalled CUDA, cuDNN, and built tensorflow from sources. This problem has been occuring since updating the Nvidia drivers to version 381.09 beta. Any help?

5
Use tf-nightly-gpu if you have CUDA 9.0 for now, until it goes stable. - OverCoder
@OverCoder I'm currently using 1.4.0-rc0 built from source with CUDA 9.0 and I've had no problems til now. Should I still switch to tf-nightly-gpu? - Harish Rajagopal
I was wrong, I misread this, you need to build from source for now. - OverCoder
I have this problem and i have cuda 9.0 installed what is the easy fix - amitnair92
@amitnair92 All you have to do is to find the path of the CUDA 9 library and add it to the environment variable LD_LIBRARY_PATH, as given in my answer. - Harish Rajagopal

5 Answers

41
votes

Found the solution:

I reinstalled nvidia-381, CUDA-8.0 (using the runfile) and cuDNN 6.0. Then I added the following in my .bashrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
9
votes

No need for reinstallation. Install nvidia-cuda-dev:

sudo apt install nvidia-cuda-dev

Install cuDNN (which you download from https://developer.nvidia.com/cudnn), and set LD_LIBRARY_PATH accordingly (to cuda/lib64).

4
votes

You could be having this problem if you installed the latest version of CUDA (9.0). If this is the case, you'll have the libcusolver.so.9.0 file or directory on your computer, but not 8.0, so python can't find it to import. Tensorflow doesn't yet support CUDA 9.0 (as of Oct 18th 2017).

To fix this, install CUDA 8.0, which can be found here. You can find all their legacy releases at the bottom of the main download page.

2
votes

I faced this error due to incompatibility between Tensorflow version with CUDA. I had tensorflow_gpu-1.3.0, CUDA 9 and cuDNN 7 which are incompatible as per this https://www.tensorflow.org/install/source#tested_build_configurations

so I uninstalled tensorflow_gpu-1.3.0 and installed tensorflow_gpu-1.5.0 and it worked fine

0
votes

In addition to having the paths correctly set, the version of Tensorflow you have installed must be compatible with the CUDA driver version you have in your system otherwise it won't work. See the link