我从源代码构建TensorFlow。构建似乎成功;但是,当我的TensorFlow程序调用{{1}}时,会出现以下一个或两个错误:
import tensorflow
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
答案 0 :(得分:61)
首先,针对以下错误:
ImportError:libcudart.so.8.0:无法打开共享对象文件:没有这样的文件或目录
确保您的LD_LIBRARY_PATH
目录包含您在cuda包中安装的lib64
目录。您可以在export
中添加.bashrc
行来执行此操作。对于奥马尔来说,它看起来如下:
我修复此问题只是将cuda路径添加到我的.bashrc
export LD_LIBRARY_PATH=/usr/local/cuda/lib64/
对我来说,我必须做Omar的路线并且还要:
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64/
因为我有两个涉及cuda的目录(可能不是最好的)。
第二,您确定安装了cuDNN吗?请注意,这与常规cuda包不同。您需要注册,然后从以下页面下载并安装该软件包: https://developer.nvidia.com/cudnn
第三次,我遇到了同样的问题:
ImportError:libcudnn.5:无法打开共享对象文件:没有这样的文件或目录
事实证明我的libcudnn.5
或/usr/local/cuda/lib64
目录中没有/usr/local/cuda-8.0/lib64
。但是,我有一个libcudnn.so.6.*
文件。为了解决这个问题,我创建了一个软链接:
ln -s libcudnn.so.6.* libcudnn.so.5
在我的/usr/local/cuda/lib64
目录中。现在一切都适合我。如果您已经有cuDNN
,并且您的libcudnn.so.6.*
可能是其他版本,那么您的目录可能会有所不同,请检查一下。
答案 1 :(得分:40)
我遇到了同样的问题
In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
40 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 41 from tensorflow.python.pywrap_tensorflow_internal import *
42 from tensorflow.python.pywrap_tensorflow_internal import __version__
/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py in <module>()
27 return _mod
---> 28 _pywrap_tensorflow_internal = swig_import_helper()
29 del swig_import_helper
/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py in swig_import_helper()
23 try:
---> 24 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
25 finally:
/usr/local/lib/python3.5/imp.py in load_module(name, file, filename, details)
241 else:
--> 242 return load_dynamic(name, filename, file)
243 elif type_ == PKG_DIRECTORY:
/usr/local/lib/python3.5/imp.py in load_dynamic(name, path, file)
341 name=name, loader=loader, origin=path)
--> 342 return _load(spec)
343
ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-a649b509054f> in <module>()
----> 1 import tensorflow
/usr/local/lib/python3.5/site-packages/tensorflow/__init__.py in <module>()
22
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import
26
/usr/local/lib/python3.5/site-packages/tensorflow/python/__init__.py in <module>()
49 import numpy as np
50
---> 51 from tensorflow.python import pywrap_tensorflow
52
53 # Protocol buffers
/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
50 for some common reasons and solutions. Include the entire stack trace
51 above this error message when asking for help.""" % traceback.format_exc()
---> 52 raise ImportError(msg)
53
54 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/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 "/usr/local/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/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.
我已经安装了cudnn 6.0,但需要libcudnn.so.5
,显然找不到libcudnn.so.5
。看来你的张量流需要cudnn 5.x,所以安装cudnn 5.x
确保您已安装cuda 8.0并导出PATH
和LD_LIBRARY_PATH
要安装cudnn 5.x,请尝试以下命令
$ tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
$ cd cuda/lib64/
$ ls -l
total 150908
lrwxrwxrwx 1 doom doom 13 Nov 7 2016 libcudnn.so -> libcudnn.so.5
lrwxrwxrwx 1 doom doom 18 Nov 7 2016 libcudnn.so.5 -> libcudnn.so.5.1.10
-rwxr-xr-x 1 doom doom 84163560 Nov 7 2016 libcudnn.so.5.1.10
-rw-r--r-- 1 doom doom 70364814 Nov 7 2016 libcudnn_static.a
在这里,您将看到2个符号链接文件,只需将libcudnn.so.5.1.10
和libcudnn_static.a
复制到/usr/local/cuda/lib64
$ cd /usr/local/cuda/lib64/
$ sudo ln -s libcudnn.so.5.1.10 libcudnn.so.5
$ sudo ln -s libcudnn.so.5 libcudnn.so
$ ls -l libcudnn*
lrwxrwxrwx 1 root root 13 May 24 09:24 libcudnn.so -> libcudnn.so.5
lrwxrwxrwx 1 root root 18 May 24 09:24 libcudnn.so.5 -> libcudnn.so.5.1.10
-rwxr-xr-x 1 root root 84163560 May 24 09:23 libcudnn.so.5.1.10
-rw-r--r-- 1 root root 70364814 May 24 09:23 libcudnn_static.a
cudnn.h
目录中的include
复制到/usr/local/cuda/include
$ sudo cp cudnn.h /usr/local/cuda/include/
希望它会对你有所帮助!
答案 2 :(得分:10)
我修复此问题只是将cuda路径添加到我的.bashrc
export LD_LIBRARY_PATH=/usr/local/cuda/lib64/
请记住,首先您需要访问nvidia Deep Learning页面,注册并下载cuDNN,将include和lib64文件夹中的文件解压缩并复制到您的cuda安装中。
答案 3 :(得分:5)
我看到了类似的错误(这篇文章的底部),但抱怨 libcudnn.so.6 而不是libcudart.so.8.0(见下面的注释)。
<强>解决方案:强>
注意:
Tensorflow安装说明(截至2017年8月20日)require installing cuDNN v5.1,但我的Tensorflow安装(遵循installing in a virtualenv的说明)需要cuDNN v6.x(由错误指示)。我不知道这是我的错误还是Tensorflow文档。不过,上述解决方案对我有用。
遇到错误:
In [1]: import tensorflow as tf
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
/home/haseeb/.virtualenvs/attention_transformer/local/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
22
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import
26
/home/haseeb/.virtualenvs/attention_transformer/local/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
47 import numpy as np
48
---> 49 from tensorflow.python import pywrap_tensorflow
50
51 # Protocol buffers
/home/haseeb/.virtualenvs/attention_transformer/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py in <module>()
50 for some common reasons and solutions. Include the entire stack trace
51 above this error message when asking for help.""" % traceback.format_exc()
---> 52 raise ImportError(msg)
53
54 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "/home/haseeb/.virtualenvs/attention_transformer/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/haseeb/.virtualenvs/attention_transformer/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/haseeb/.virtualenvs/attention_transformer/local/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: libcudnn.so.6: 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.
答案 4 :(得分:3)
截至目前,张量流支持cuda-9.0
做以下事情。希望它有所帮助:
$ sudo apt-get install cuda-9.0
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64
下载cuDNN for 9.0(您需要在下载前注册) https://developer.nvidia.com/rdp/form/cudnn-download-survey
$ sudo dpkg -i libcudnn7_7.1.2.21-1+cuda9.0_amd64.deb
关闭所有终端并打开新
$ source activate tensorflow
$ python
>> import tensorflow as tf
此后你不应该收到任何错误。
答案 5 :(得分:1)
上述错误通常是由于在运行configure
脚本时未指定Cuda SDK或cuDNN的版本号而引起的。换句话说,在运行configure
脚本时,请始终指定版本号以响应以下两个问题:
Please specify the Cuda SDK version you want to use, e.g. 7.0.
Please specify the cuDNN version you want to use.
不接受系统默认值。
答案 6 :(得分:1)
在MacOS上,此问题通常是由沙箱环境中运行的bazel引起的,因此不尊重本地shell中设置的LD_LIBRARY_PATH。我不打算深入了解在构建工具中深度集成沙盒的优点。
简单的解决方法是将库符号链接到/ usr / local / lib。
cd /usr/local/lib && ln -s ../cuda/lib/libcudart.8.0.dylib
答案 7 :(得分:1)
首先,从here
安装CUDA库(版本7.5)安装说明:
1- sudo dpkg -i cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
2- sudo apt-get update
3- sudo apt-get install cuda
其次,从here安装cuDNN
第三,导出cuDNN路径:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64/
如果您遇到“需要重新安装软件包libcudnnX ”这样的错误,请按以下步骤进行操作here
答案 8 :(得分:1)
检查 NVIDIA要求以支持GPU支持运行TensorFlow (link):
CUDA®Toolkit8.0
与CUDA Toolkit 8.0相关的NVIDIA驱动程序
cuDNN v6.0
使用CUDA Compute 功能3.0 或更高的GPU卡
libcupti-dev库,它是NVIDIA CUDA配置文件工具界面
我安装了cuda v5.1,下面的消息仍然是:
ImportError: libcudart.so.8.0: cannot open shared object file:
No such file or directory
我因为一切看起来很好而生气,所以我决定用命令检查我的GPU(在Linux上):
glxinfo | grep GeForce
我注意到我的NVIDIA GPU不受支持:
OpenGL renderer string: **GeForce GTX 560M**/PCIe/SSE2
在此link中,您可以找到一个列表,如:
所以我的解决方案是在没有GPU支持的情况下使用张量流。所以我这样做:
pip uninstall tensorflow-gpu
我安装了多个支持:
pip install tensorflow
答案 9 :(得分:0)
TensorFlow 1.2.1与cuDNN 5.1兼容,但尚未与6.0兼容。所以只需安装cuDNN 5.1。除此之外,你似乎错过了CUDA 8.0。
答案 10 :(得分:0)
与GPU,CUDA和Docker相关的常见变通办法一般问题:
A。。如果要处理与机器学习/深度学习相关的部署,请使用nvidia-docker,而不要使用native-docker。要安装nvidia-docker,请执行以下简单步骤。
Docker容器与平台无关,但与硬件无关。当使用需要内核模块和用户级库才能运行的专用硬件(例如NVIDIA GPU)时,这会带来问题。结果,Docker本身不支持容器内的NVIDIA GPU。
B。。如果您想使用docker访问GPU,请不要从头开始构建容器,这会给您带来很多错误。而是只使用Nvidia-Docker集线器中的任何容器。选择任何特定的映像,复制其Dockerfile并运行sudo nvidia-docker build -t happyapp .
。 [happyapp是您的新应用名称]。在5分钟内,您将准备好容器(取决于网络速度:p)。
C 。如果要在其上安装和运行Tensorflow,请不要下载具有任何cuda / cudnn版本的nvidia-docker。如果这样做,将出现与 libcudnn.so.6 或 libcudnn.so.9 或 libcusolver.so.8.0 相关的错误,并且您将几乎无法解决这个错误。
相反,只需使用预构建的Tensorflow Docker映像:sudo nvidia-docker run -it tensorflow/tensorflow:latest-gpu /bin/bash