TensorFlow之Win10安装填坑笔记(Anaconda、GPU版)

2019-04-14 08:28发布

第一次在win10上安装GPU版的TensorFlow,安装过程中有个坑让我装了五六遍…
安装以后,具体错误提示如下 大致如下: ImportError: DLL load failed: 找不到指定的模块。 ImportError: No module named '_pywrap_tensorflow_internal' Failed to load the native TensorFlow runtime. 详细错误: >>> import tensorflow as tf Traceback (most recent call last): File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 18, in swig_import_helper return importlib.import_module(mname) File "D:DevProgramsanacondaenvs ensorflowlibimportlib\__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:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow.py", line 41, in from tensorflow.python.pywrap_tensorflow_internal import * File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 21, in _pywrap_tensorflow_internal = swig_import_helper() File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow_internal') File "D:DevProgramsanacondaenvs ensorflowlibimportlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_pywrap_tensorflow_internal' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflow\__init__.py", line 24, in from tensorflow.python import * File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpython\__init__.py", line 49, in from tensorflow.python import pywrap_tensorflow File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow.py", line 52, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 18, in swig_import_helper return importlib.import_module(mname) File "D:DevProgramsanacondaenvs ensorflowlibimportlib\__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:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow.py", line 41, in from tensorflow.python.pywrap_tensorflow_internal import * File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 21, in _pywrap_tensorflow_internal = swig_import_helper() File "D:DevProgramsanacondaenvs ensorflowlibsite-packages ensorflowpythonpywrap_tensorflow_internal.py", line 20, in swig_import_helper return importlib.import_module('_pywrap_tensorflow_internal') File "D:DevProgramsanacondaenvs ensorflowlibimportlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_pywrap_tensorflow_internal' 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.安装cuda及cudnn(解压、添加环境变量、复制到cuda文件夹)
2.安装anaconda,值得注意的当前的anaconda3默认的python版本为3.6,需要在安装后执行conda install python=3.5.2,值得注意的是这家伙安装之后不会出自己退出…(推荐使用清华源)
3.安装
conda create -n tensorflow python=3.5.2设置安装环境
activate tensorflow激活环境
pip install --ignore-installed --upgrade tensorflow_gpu-1.2.1-cp35-cp35m-win_amd64.whl(去清华源先下载了,安装本地安装包)
4.测试
python -V查看python版本
python运行Python
import tensorflow as tf导入tensorflow
然后就出现上面的错误了。。。
④解决办法 https://stackoverflow.com/questions/42011070/on-windows-running-import-tensorflow-generates-no-module-named-pywrap-tenso 的回答 In my case the "cudnn64_6.dll" file in the /bin folder had to be renamed to "cudnn64_5.dll" for the error to go away. I easily spent two hours to figure this out, and I followed the official install guide to the letter. This is true for installation via pip (officially supported) and conda (community supported). This was my case. TensorFlow requires "cuDNN v5.1" but if you install cuDNN v6.0, then the file name of the cudnn dll file will be cudnn64_6.dll not cudnn64_5.dll. – Naetmul Jun 13 at 12:17 大致意思是层主通过把cudnn64_6.dll这个链接库的名字改为cudnn64_5.dll之后就可以用了,然后别人回复,windows版的tensorflow支持cudnn5.1,然而我们安装了6.0,所以会这样,回看官网的说明
这里写图片描述
的确如此…