TensorFlow之Win10安裝填坑筆記(Anaconda、GPU版)

第一次在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:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", 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:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\importlib\__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 "<stdin>", line 1, in <module>
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 906, in create_module
  File "<frozen importlib._bootstrap>", 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:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "D:\DevPrograms\anaconda\envs\tensorflow\lib\importlib\__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,所以會這樣,回看官網的說明
這裏寫圖片描述
的確如此…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章