windows安装TensorFlow gpu版本时候的bug;No module named "_pywrap_tensorflow" ;DLL load failed.

安装TensorFlow时候只要按照官方文档(点击打开链接)一步一步的的走大致没有其他问题,但是在运行文档给出的示例时候会出现一下bug,

import tensorflow as tf
Traceback (most recent call last):
  File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "D:\Program Files\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 986, in _gcd_import
  File "", line 969, in _find_and_load
  File "", line 958, in _find_and_load_unlocked
  File "", line 666, in _load_unlocked
  File "", line 577, in module_from_spec
  File "", line 906, in create_module
  File "", line 222, in _call_with_frames_removed
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in 
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in 
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "D:\Program Files\Python35\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'
在debug的时候找了两篇文档( 博客一  博客二 )都提到了相关问题,说法也一样,但是他们的说法都不完全正确,结合官方文档中的FAQ,在这里给出相对完善的解决思路:

1. 在按照官方文档安装cuDNN的过程中有如下步骤:

Copy the following files into the CUDA Toolkit directory.
a) Copy \cuda\bin\cudnn64_7.dll to C:\Program Files
\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.
b) Copy \cuda\ include\cudnn.h to C:\Program Files
\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include.
c) Copy \cuda\lib\x64\cudnn.lib to C:\Program Files
\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64.
在完成之后一定要将放有以上三个文件的文件夹加入到系统变量CUDA_PATH 和path中去;(这是以上两篇博客和官方文档在开头强调的,但是人会报错);重启命令行。

2. 这一点比较隐藏,由于部分版本更新导致文件命名可能不是同一,一定要将cudnn64_7.dll 改成cudnn64_5.dll。因为TensorFlow原来支持的是5.1版本。具体解释看Stack Overflow(点击打开链接)中第二个回答部分。重启命令行。

3. 当然可能还有其他更多原因。可以看看2步中其他的回答或是其他博客。


你可能感兴趣的:(技术问题)