【问题标题】:Import error after installing tensorflow安装tensorflow后导入错误
【发布时间】:2017-05-12 19:03:46
【问题描述】:

我尝试安装链接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.

【问题讨论】:

  • 为什么要将导入错误放在 pastebin 链接中?将其编辑到您的问题中。
  • 嗯,它很长,这就是原因。无论如何,我会编辑问题。
  • 请检查strace python -c "import tensorflow" 2&gt;&amp;1 &gt; /dev/null | grep libcudnn的输出。是否有任何搜索位置错误地失败?权限错误?如果没有任何不妥之处,您能否将其包含在您的帖子中?

标签: python-3.x tensorflow virtualenv cudnn


【解决方案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版本更改文件名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2021-11-17
    相关资源
    最近更新 更多