在之前的学习中已经安装并启动好了tensorflow,但一段时间没有使用之后,再次启动后却出现了报错:
(tensorflow) C:\Users\Administrator>python Python 3.6.3 |Anaconda, Inc.| (
default, Nov 8 2017, 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.
这里的启动方式是先打开anaconda prompt窗口,然后输入activate tensorflow命令后,再进入python环境,再输入import
tensorflow后报错,如下所示:

在网上搜寻解决方法,大致有以下几种解决方法:

* 错误提示为DLL load failed,说明缺少一些必须的DLL模块,可以尝试安装Microsoft Visual C++ 2015
Redistributable <http://www.microsoft.com/en-us/download/details.aspx?id=52685>
程序(如这里的介绍 <https://blog.csdn.net/u011799895/article/details/81703549>或者这篇博文
<https://blog.csdn.net/z137628817/article/details/78021066>)。
* 在anaconda中重新安装tensorflow。可参考这篇博文 <https://www.jianshu.com/p/fd27a586f8c2>
中最后给出的调试代码来进行bug检查,逐步排查错误。
*
重新配置cuda和cudnn模块。可能是之前用别的深度学习模块时,改变了cuda和cudnn的配置。检查一下电脑中的cuda和cudnn配置,改为cuda8.0和cudnn-8.0-windows10-x64-v6.0版本(或其他和tensorflow配套的版本)。
尝试上述的3种方法也许可以解决tensorflow启动报错:DLL load failed的问题。