(解决方法)tensorflow ImportError: DLL load failed: 找不到指定的模块。

pip install tensorflow后,运行import tensorflow 没有错误,但是运行测试程序,

import tensorflow as tf
h = tf.constant("hell,TF")
sess=tf.Session()
print(sess.run(h))

出现错误如下:

Traceback (most recent call last):
  File "E:/机器学习/untitled/tsfl.py", line 1, in <module>
    import tensorflow as tf
  File "D:\Pycharm\Python3.6\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "D:\Pycharm\Python3.6\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "D:\Pycharm\Python3.6\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "D:\Pycharm\Python3.6\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "D:\Pycharm\Python3.6\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "D:\Pycharm\Python3.6\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:\Pycharm\Python3.6\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "D:\Pycharm\Python3.6\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块

查询后发现了一些方案,没有成功。比如装一个Anaconda; 要装个visual studio2017……

还有如下网址的解决方案

https://www.cnblogs.com/native-hadoop/p/7724481.html

在官网下载Microsoft Visual C++ 2015 Redistributable Update 3

https://www.microsoft.com/en-us/download/details.aspx?id=53587

结果发现电脑已经装好Microsoft Visual C++ 2015 Redistributable Update 3 ,依旧没有解决问题。

查阅Tensorflow官网,按照windows的正确配置方法来进行

https://www.tensorflow.org/install/source_windows

 

经过测试的构建配置

原安装为win10 + python3.6 + CUDA10 + cudnnv7.5.0 + tensorflow1.13.1 + NVIDIA GTX 1050 检查后发现出现该问题的原因为版本不匹配。

解决:修改为win10 + python3.6 + CUDA9.0 + cudnn v7.3 + tensorflow1.12.0

1.首先在NVIDIA 控制面板中查看显卡 支持的CUDA版本,具体方法参考《Windows系统查看CUDA版本号》,地址如下https://www.jianshu.com/p/d3b9419a0f89(如果打不开NVIDIA控制面板,可重装驱动)

 

本电脑支持CUDA9.2及以下版本

故需重装CUDA,卸载方法参考(亲测CUDA10依然有效) https://blog.csdn.net/xuefengyang666/article/details/79422012

CUDA9.0 和 对应cudnn的安装包及安装方法参考https://blog.csdn.net/xuefengyang666/article/details/79422012

2.修改tensorflow的版本(不修改可能也有效)

pip install tensorflow-gpu==1.12.0

版本匹配后,再执行测试程序则能正常运行,问题解决。

展开阅读全文

没有更多推荐了,返回首页