安装tensorflow

时间:2017-05-12 19:03:46

标签: python-3.x tensorflow virtualenv cudnn

我尝试按照链接Installing Tensor flow

中的说明安装tensorflow

我在虚拟环境中安装了它。我收到编辑结尾时给出的导入错误。

我设置了以下环境变量。

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/

此外,我还尝试手动复制cudnn的文件,但仍然没有运气。也就是说,/usr/local/cuda/lib64/usr/local/cuda-8.0/lib64都有libcudnn.so.5。

正如其他相关帖子所述,问题通常是由环境路径引起的,但我觉得它们在我的情况下非常正确,但仍然存在错误。

请帮忙!

编辑 - 这是完整的错误追溯 -

(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.

1 个答案:

答案 0 :(得分:1)

我认为你的libcudnn.so文件没有正确链接。

请做

$ sudo ldconfig

这将显示/path/to/cuda-8.0/lib64中未正确链接的文件。 这些应该是libcudnn.so和libcudnn.so.5(根据你的错误)。

尝试在终端上尝试以下命令: 如果你有cudnn v6(就像我有的话):

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

如果您已从NVIDIA CUDNN软件包手动复制这些文件夹,请从此文件夹中删除libcudnn.so.6和libcudnn.so。

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

请根据您使用的cudnn版本更改文件名。