python - ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。(导入 tensorflow 错误)
问题描述
import tensorflow as tf Traceback(最近一次调用最后):文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”,第 58 行,来自 tensorflow.python.pywrap_tensorflow_internal import *文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 28 行,在 _pywrap_tensorflow_internal = swig_import_helper() 文件“E:\path\envs\py36_tf_cpu\lib\site- packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 24 行,在 swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 文件“E:\path\envs\py36_tf_cpu\lib\imp.py”中,第 243 行,在 load_module 返回 load_dynamic(name, filename, file) File "E:\path\envs\py36_tf_cpu\lib\imp.py",第 343 行,在 load_dynamic 返回 _load(spec) ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。
在处理上述异常的过程中,又出现了一个异常:
Traceback(最近一次调用最后):文件“”,第 1 行,在文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow__init__.py”,第 22 行,in from tensorflow.python import pywrap_tensorflow # pylint :禁用=未使用的导入文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python__init__.py”,第 49 行,从 tensorflow.python 导入 pywrap_tensorflow 文件“E:\path\envs\py36_tf_cpu \lib\site-packages\tensorflow\python\pywrap_tensorflow.py",第 74 行,在 raise ImportError(msg) ImportError: Traceback (last recent call last): File "E:\path\envs\py36_tf_cpu\lib\site- packages\tensorflow\python\pywrap_tensorflow.py”,第 58 行,从 tensorflow.python.pywrap_tensorflow_internal 导入 * 文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 28 行,在 _pywrap_tensorflow_internal = swig_import_helper() 文件“E:\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\ python\pywrap_tensorflow_internal.py”,第 24 行,在 swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 文件“E:\path\envs\py36_tf_cpu\lib\imp.py”,第 243 行,在load_module return load_dynamic(name, filename, file) File "E:\path\envs\py36_tf_cpu\lib\imp.py", line 343, in load_dynamic return _load(spec) ImportError: DLL load failed: A dynamic link library (DLL ) 初始化例程失败。\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 24 行,在 swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 文件“E:\path\ envs\py36_tf_cpu\lib\imp.py”,第 243 行,在 load_module 返回 load_dynamic(name, filename, file) 文件“E:\path\envs\py36_tf_cpu\lib\imp.py”,第 343 行,在 load_dynamic 返回 _load (spec) ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。\path\envs\py36_tf_cpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”,第 24 行,在 swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 文件“E:\path\ envs\py36_tf_cpu\lib\imp.py”,第 243 行,在 load_module 返回 load_dynamic(name, filename, file) 文件“E:\path\envs\py36_tf_cpu\lib\imp.py”,第 343 行,在 load_dynamic 返回 _load (spec) ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。文件)文件“E:\path\envs\py36_tf_cpu\lib\imp.py”,第 343 行,在 load_dynamic 返回 _load(spec) ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。文件)文件“E:\path\envs\py36_tf_cpu\lib\imp.py”,第 343 行,在 load_dynamic 返回 _load(spec) ImportError: DLL load failed: 动态链接库 (DLL) 初始化例程失败。
无法加载原生 TensorFlow 运行时。
见https://www.tensorflow.org/install/install_sources#common_installation_problems
出于一些常见的原因和解决方案。寻求帮助时,请在此错误消息上方包含整个堆栈跟踪。
解决方案
截至 2019 年 4 月,我通过安装CUDA 10.0(不是 10.1 或 9.x !!!)和cuDNN 7.5.0解决了 Windows 10 / Python 3.6.x / GPU RTX 20xx 下的“DLL 加载失败”问题。我还安装了 Visual Studio 2015。
如果您有 CUDA 10.1,请卸载它,安装 10.0,然后重新启动。将来自 cuDNN 的文件放在 CUDA 安装的相应目录中。不要忘记将 cuDNN*.dll
文件的位置(/bin/
CUDA 安装文件夹)添加到 PATH。
可以使用pip install tensorflow-gpu
(当前版本 1.13.1)安装 TensorFlow。
您可以使用以下方法测试 GPU 是否已注册:
import tensorflow as tf
import keras
config = tf.ConfigProto( device_count = {'GPU': 1 , 'CPU': 56} )
sess = tf.Session(config=config)
keras.backend.set_session(sess)
推荐阅读
- r - 用R造句造句
- linq - 在 LINQ 结构中使用 Group By 和 Have 子句的 SQL 查询
- r - 在函数中引用脚本变量
- apache-spark - 根据列中的最大值将行合并到映射类型
- reactjs - 我如何 wrapper.find() material-ui classNames 用 jest 和酵素进行测试?
- node.js - 使用 Post 方法将使用 NodeJS 存储在我的计算机中的 CSV 文件发送到另一台服务器
- python - 使用子进程 popen 时 tkinter 冻结
- reactjs - 使用 babel-plugin-react-css-modules 将 css 模块作为 prop 传递
- python - 使用 LSTM 预测函数 f(x) 的 100 个值
- autohotkey - 如何在自动热键中组合热键中的键?