2017-05-31 1047 views
0

我试图在Windows 7上安装TensorFlow(未GPU版)“没有名为pywrap_tensorflow_internal模块”我已经安装了Python 3.5.2,我可以证实:TensorFlow导入错误:“DLL加载失败”和

$ python --version 
Python 3.5.2 

我安装TensorFlow使用下面的命令,它似乎工作:

$ pip3 install --upgrade tensorflow 

但是,当我进入了Python shell来验证安装,我得到这个错误:

>>> import tensorflow as tf 
Traceback (most recent call last): 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper 
    return importlib.import_module(mname) 
    File "C:\Users\kimlesj1\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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> 
    from tensorflow.python.pywrap_tensorflow_internal import * 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> 
    _pywrap_tensorflow_internal = swig_import_helper() 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper 
    return importlib.import_module('_pywrap_tensorflow_internal') 
    File "C:\Users\kimlesj1\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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\__init__.py", line 24, in <module> 
    from tensorflow.python import * 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module> 
    from tensorflow.python import pywrap_tensorflow 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module> 
    raise ImportError(msg) 
ImportError: Traceback (most recent call last): 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper 
    return importlib.import_module(mname) 
    File "C:\Users\kimlesj1\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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module> 
    from tensorflow.python.pywrap_tensorflow_internal import * 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module> 
    _pywrap_tensorflow_internal = swig_import_helper() 
    File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper 
    return importlib.import_module('_pywrap_tensorflow_internal') 
    File "C:\Users\kimlesj1\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_problems 

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

我们已经创建了一个脚本来帮助调试这种错误。你可以尝试下载并运行代码[这里](https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c),并按照其建议。 (由于您没有使用GPU版本,因此您可以忽略有关CUDA的警告......最有可能找不到msvcp140.dll库,并且可以从[here](https: //www.microsoft.com/en-us/download/details.aspx?id=53587)。) – mrry

+0

谢谢!你是对的,我缺少'msvcp140.dll',并且能够在安装TensorFlow后使用它。 –

回答

0

脚本tensorflow_self_check.py对我来说很完美。它指出我错过了cuDNN v6的文件cudnn64_6.dll。需要注意的是,在TensorFlow窗口官方指南(https://www.tensorflow.org/install/install_windows)中,他们坚持认为它必须是cuDNN v5.1和cuDNN64_5.dll!他们应该通过添加tensorflow_self_check.py脚本来更新本指南。

编辑:我应该仔细阅读TensorFlow 1.3.0 https://github.com/tensorflow/tensorflow/blob/r1.3/RELEASE.md的发布说明:“我们所有的预先构建的二进制文件都是用cuDNN 6构建的。我们预计将发布含有cuDNN 7的TensorFlow 1.4。”

1

就我而言,cudnn v5或v6不能单独工作。我看着自检脚本,似乎都cudnn64_5.dll和cudnn64_6.dll的正确安装进行检查:

cudnn5_found = False 
try: 
    cudnn5 = ctypes.WinDLL("cudnn64_5.dll") 
    cudnn5_found = True 
except OSError: 
    candidate_explanation = True 
    print(""" 
    - Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow 
    requires that this DLL be installed in a directory that is named in 
    your %PATH% environment variable. Note that installing cuDNN is a 
    separate step from installing CUDA, and it is often found in a 
    different directory from the CUDA DLLs. You may install the 
    necessary DLL by downloading cuDNN 5.1 from this URL: 
    https://developer.nvidia.com/cudnn""") 

cudnn6_found = False 
try: 
    cudnn = ctypes.WinDLL("cudnn64_6.dll") 
    cudnn6_found = True 
except OSError: 
    candidate_explanation = True 

if not cudnn5_found or not cudnn6_found: 
    print() 
    if not cudnn5_found and not cudnn6_found: 
    print("- Could not find cuDNN.") 
    elif not cudnn5_found: 
    print("- Could not find cuDNN 5.1.") 
else: 
    print("- Could not find cuDNN 6.") 
    print(""" 
    The GPU version of TensorFlow requires that the correct cuDNN DLL be 
    installed 
    in a directory that is named in your %PATH% environment variable. Note 
    that 
    installing cuDNN is a separate step from installing CUDA, and it is often 
    found in a different directory from the CUDA DLLs. The correct version of 
    cuDNN depends on your version of TensorFlow: 

    * TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll') 
    * TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll') 

如果任何V5或V6没有在路径发现,将发生OSERROR。所以我把两个都放在我的Path环境变量中,并且检查通过了。

相关问题