2017-05-20 409 views
2

在嘗試驗證tensorflow-gpu的安裝時,在嘗試執行「將tensorflow導入爲tf」時,出現ImportError錯誤。我在Windows 7上使用Quadro K620。使用pip安裝Tensorflow。No Module named'_pywrap_tensorflow_internal'

以下是堆棧跟蹤:

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 

C:\Users\aagarwal>python 
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM 
D64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import tensorflow as tf 
Traceback (most recent call last): 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_hel 
per 
    return importlib.import_module(mname) 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\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: The specified module could not be found. 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> 
    from tensorflow.python.pywrap_tensorflow_internal import * 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> 
    _pywrap_tensorflow_internal = swig_import_helper() 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_hel 
per 
    return importlib.import_module('_pywrap_tensorflow_internal') 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\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' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\__init__.py", line 24, in <module> 
    from tensorflow.python import * 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\__init__.py", line 51, in <module> 
    from tensorflow.python import pywrap_tensorflow 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow.py", line 52, in <module> 
    raise ImportError(msg) 
ImportError: Traceback (most recent call last): 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_hel 
per 
    return importlib.import_module(mname) 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\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: The specified module could not be found. 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> 
    from tensorflow.python.pywrap_tensorflow_internal import * 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> 
    _pywrap_tensorflow_internal = swig_import_helper() 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\Python35\lib\site-packag 
es\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_hel 
per 
    return importlib.import_module('_pywrap_tensorflow_internal') 
    File "C:\Users\aagarwal\AppData\Local\Programs\Python\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' 


Failed to load the native TensorFlow runtime. 

See https://www.tensorflow.org/install/install_sources#common_installation_probl 
ems 

for some common reasons and solutions. Include the entire stack trace 
above this error message when asking for help. 
>>> 

我已經看過多個其他哪些東西喜歡修正路徑堆棧溢出的職位,但我一直沒能解決這個問題。

+0

可能重複[無法在Windows 10上導入Tensorflow for GPU](https://stackoverflow.com/questions/43577923/cannot-import-tensorflow-for-gpu-on-windows -10) – aldel

回答

3

我碰到今天同樣的問題來了,請切換到cuDNN V5.1庫Windows,而不是作爲@mickdelaney建議,然後嘗試

  1. 檢查CUDA的環境設置,通常CUDA的所有設置都已添加到Windows環境中

  2. 將cuDNN的bin,libinclude中的文件分別複製到CUDA的bin,libinclude。通常目錄是C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

然後你可以導入張量流並運行你的代碼。祝你好運!

1

安裝CUDA驅動程序後,您必須下載cuDNN並將其發佈。之後,您可以將cudnn64_5.dll複製到PATH。
如果這不起作用,請將cudnn64_5.dll移動到 NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin,然後再試一次。否則,你會遇到一些你看到的錯誤。

0

安裝cuDNN 5.1後,仍然出現此錯誤(是的,我已正確設置PATH)。我從this site安裝tensorflow_gpu更好。這需要cuDNN 6.0,而不是5.1。不幸的是,他們目前只有GPU系統的Tensorflow 1.1。

0

我是中國人,所以我的英語是游泳池,而我的答案是,無論您使用cudnn 7還是6或5,您都必須在複製文件後將dll從cudnn64_x.dll重命名爲cudnn64_6.dll。 也許很快,您需要將dll重命名爲7或8或9。

算了,寫點中文吧,我特麼就不明白了爲啥TF導入的DLL一定要用cudnn64_6? 難道不能直接寫成cudnn64或者cudnn? 反正現在cudnn 7也出來了,難道以後用最新的庫都要改改名字嗎?