在windows10下尝试安装高版本的tensorflow,需要GPU的支持,安装了CUDA9.0,下载了cudnn7.0.5以后,运行import tensorflow报错,报错信息如下,大概一丝就是DLL文件没有找到
Traceback (most recent call last):
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\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 "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_init_.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\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 "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Darshan\AppData\Local\Programs\Python\Python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Failed to load the native TensorFlow runtime.
在Tensorflow的github中的issue里有大量讨论,https://github.com/tensorflow/tensorflow/issues/22794但是在我看来没有什么用,我从头到尾看了一遍,各种的尝试都是摸瞎,而且方法很少,报问题的很多。
看到报错的问题,就是DLL文件没有找到,但是查看报错的文件,只是tensorflow封装的pyd文件,难以找到到底是哪个DLL文件的缺失,但是从讨论看普遍是CUDA或者是cudnn文件的适配问题。猜想还是cudnn文件里的DLL文件没有load进来的问题,于是仔细查看cudnn的安装文档:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html,找到了一个关键的操作:
Copy the following files into the CUDA Toolkit directory.
Copy
Copy
Copy
在Tensorflow的官网给出的安装cudnn的操作中,只是将cudnn的文件解压到如C:\tools\cuda,并不需要把cudnn的文件拷贝到CUDA的安装目录中,去检查CUDA的这几个文件夹,发现确实在文件夹中没有指定文件,拷贝进去后,成功的运行了Tensorflow没有再报错找不到DLL。
版本信息:
Nvidiai显卡:GTX 1050
驱动版本:419.17
TensorFlow版本:1.12
CUDA版本:9.0
CUDNN版本:7.0.5
如果觉得本文对你有帮助的话,不妨扫码请笔者喝杯茶