安装tensorflow-gpu:ImportError: DLL load failed:找不到指定的模块 原因&解决方案

在按照教程安装tensorflow-gpu的过程中,出现ImportError: DLL load failed:找不到指定的模块:

(tensorflow) C:\Users\Administrator>python
Python 3.6.3 |Anaconda, Inc.| (default, Mar  4 2019, 15:10:56) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\ProgramFiles\Anaconda\envs\tensorflow\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。


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.错误提示为DLL load failed,说明缺少一些必须的DLL模块,可以尝试安装Microsoft Visual C++ 2015 Redistributable程序。
2.在anaconda中重新安装tensorflow。
3.重新配置cuda和cudnn模块。可能是之前用别的深度学习模块时,改变了cuda和cudnn的配置。检查一下电脑中的cuda和cudnn配置,改为cuda8.0和cudnn-8.0-windows10-x64-v6.0版本(或其他和tensorflow配套的版本)。

尝试上述的3种方法也许可以解决tensorflow启动报错:DLL load failed的问题。
虽然通过以上几种方法确实可以解决问题,但是方法并不直接,没有找到缺少DLL的直接原因

可以通过类似于下面的方法确定缺少的DLL(通过dumpbin.exe确定依赖的DLL):

"c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\dumpbin.exe" /dependents C:\Users\username\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\_pywrap_tensorflow_internal.pyd

得到的输出类似于:
KERNEL32.dll WSOCK32.dll WS2_32.dll SHLWAPI.dll nvcuda.dll cublas64_80.dll cufft64_80.dll curand64_80.dll cudnn64_6.dll python36.dll MSVCP140.dll VCRUNTIME140.dll

然后通过搜索文件找出缺少的DLL,谷歌搜索确定DLL来自于哪里,装上对应版本的模块(可能是Microsoft Visual C++ 2015 Redistributable没装、tensorflow版本和cuda版本不一致)。

在遇到这个问题的时候,本人的原因在于cuda版本不对导致缺少DLL,通过DLL找到对应的cuda版本为10.0,最后安装的版本为tensorflow-gpu 1.13.1 + cuda 10.0 + cudnn 7.4.2(原错误版本为cuda 10.1)。

方法来源:https://github.com/tensorflow/tensorflow/issues/7623
在这里插入图片描述

  • 6
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
这个问题可能是由于缺少相应的模块导致的。根据引用中的解决方案,你可以尝试以下步骤来解决这个问题: 1. 确保你已经正确安装了相应的模块。比如,在使用`import numpy`时出错,可以尝试使用`pip install numpy`来安装最新版本的numpy包。 2. 如果安装时出现了版本不匹配的错误,可以尝试寻安装与你的程序兼容的版本。例如,在引用中,作者遇到了与PyQt5版本不匹配的问题,通过安装`PyQtWebEngine-Qt5`包来解决。 3. 如果以上步骤都没有解决问题,你可以尝试使用国内镜像网站进行安装。例如,在引用中,作者使用了清华大学镜像网站进行安装tensorflow-gpu指定版本。 总结起来,你可以通过检查安装模块是否正确,尝试安装兼容的版本,以及使用国内镜像网站来解决`import -jpype importerror: dll load failed: 不到指定模块`的问题。123 #### 引用[.reference_title] - *1* [import numpy出现ImportError: DLL load failed: 不到指定模块解决方案](https://blog.csdn.net/weixin_43178406/article/details/130545314)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [PyQtWebEngine from PyQt5.QtWebEngineWidgets import *:ImportError: DLL load failed / 不到指定的...](https://blog.csdn.net/qq_33253054/article/details/129756634)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [tensorflow在import时提示错误--ImportError: DLL load failed: 不到指定模块——解决办法](https://blog.csdn.net/weixin_42649699/article/details/106984656)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值