简体   繁体   中英

Import error after installing tensorflow

I tried installing tensorflow as given in the link Installing Tensor flow

I installed it inside virtual environment. I am getting import error as given at the end in edit.

I've set the following environment variables.

PATH=/usr/local/cuda-8.0/bin:rest/of/the/path
LD_LIBARY_PATH=/home/harshit/Drivers/cudnn5.0/cuda/:/usr/local/cuda-8.0/lib64/:/usr/local/cuda/lib64/

Moreover, I also tried manually copying the files of cudnn but still no luck. That is, I have libcudnn.so.5 in both /usr/local/cuda/lib64 and /usr/local/cuda-8.0/lib64 .

As given in other related posts, problem is usually due to environment paths but I feel they are quite correct in my case, but still error persists.

Please help!

Edit- Here is the complete error traceback-

(env) harshit@echo:~$ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcudnn.so.5: 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 "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/harshit/Documents/projects/tensorflowplay/env/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcudnn.so.5: 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 think your libcudnn.so files are not linked correctly.

Please do

$ sudo ldconfig

This will show you the files in /path/to/cuda-8.0/lib64 that are not linked properly. These should be libcudnn.so and libcudnn.so.5 (as per your error).

Try to attempt the following commands on your terminal: If you have cudnn v6 (like I have):

$ cd /path/to/cuda-8.0/lib64

Please remove libcudnn.so.6 and libcudnn.so from this folder if you have copied these manually from the NVIDIA CUDNN package.

$ sudo ln -s libcudnn.so.6.0.21 libcudnn.so.6
$ sudo ln -s libcudnn.so.6 libcudnn.so
$ sudo ldconfig

Please change the file names according to the version of cudnn you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM