Python3.5 win10环境下导入kera/tensorflow报错的解决方法


Posted in Python onDecember 19, 2019

本文实例讲述了Python3.5 win10环境下导入keras/tensorflow报错的解决方法。分享给大家供大家参考,具体如下:

我在win10 Python3.5.2安装keras,然后导入时报错如下:

Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
  return importlib.import_module(mname)
 File "d:\Anaconda3\envs\tf\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 "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
  from tensorflow.python.pywrap_tensorflow_internal import *
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
  _pywrap_tensorflow_internal = swig_import_helper()
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
  return importlib.import_module('_pywrap_tensorflow_internal')
 File "d:\Anaconda3\envs\tf\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 "d:\Anaconda3\envs\tf\lib\site-packages\keras\__init__.py", line 3, in <module>
  from . import activations
 File "d:\Anaconda3\envs\tf\lib\site-packages\keras\activations.py", line 4, in <module>
  from . import backend as K
 File "d:\Anaconda3\envs\tf\lib\site-packages\keras\backend\__init__.py", line 73, in <module>
  from .tensorflow_backend import *
 File "d:\Anaconda3\envs\tf\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in <module>
  import tensorflow as tf
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
  from tensorflow.python import *
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module>
  from tensorflow.python import pywrap_tensorflow
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
  raise ImportError(msg)
ImportError: Traceback (most recent call last):
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
  return importlib.import_module(mname)
 File "d:\Anaconda3\envs\tf\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 "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
  from tensorflow.python.pywrap_tensorflow_internal import *
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
  _pywrap_tensorflow_internal = swig_import_helper()
 File "d:\Anaconda3\envs\tf\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
  return importlib.import_module('_pywrap_tensorflow_internal')
 File "d:\Anaconda3\envs\tf\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.

又臭又长的问题说导入keras时先导入TensorFlow,然后出现导入失败,解决方法有两个:

一.安装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:

pip uninstall tensorflow
pip uninstall tensorflow-gpu

然后再重装:

pip install tensorflow
pip install tensorflow-gpu

再重新导入应该不会报错了。

如果无法解决,看下面的方法:

二.cmd下敲命令:

pip install --upgrade --ignore-installed setuptools

更多关于Python相关内容可查看本站专题:《Python数学运算技巧总结》、《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》

希望本文所述对大家Python程序设计有所帮助。

Python 相关文章推荐
Python中type的构造函数参数含义说明
Jun 21 Python
win7上python2.7连接mysql数据库的方法
Jan 14 Python
pandas创建新Dataframe并添加多行的实例
Apr 08 Python
解决python线程卡死的问题
Feb 18 Python
python assert的用处示例详解
Apr 01 Python
react+django清除浏览器缓存的几种方法小结
Jul 17 Python
python设置随机种子实例讲解
Sep 12 Python
使用pyinstaller逆向.pyc文件
Dec 20 Python
2021年的Python 时间轴和即将推出的功能详解
Jul 27 Python
pycharm激活方法到2099年(激活流程)
Sep 22 Python
Django模板报TemplateDoesNotExist异常(亲测可行)
Dec 18 Python
Python实现socket库网络通信套接字
Jun 04 Python
解决Python列表字符不区分大小写的问题
Dec 19 #Python
简单了解为什么python函数后有多个括号
Dec 19 #Python
解决Python使用列表副本的问题
Dec 19 #Python
python读写Excel表格的实例代码(简单实用)
Dec 19 #Python
python装饰器原理与用法深入详解
Dec 19 #Python
python列表生成器迭代器实例解析
Dec 19 #Python
Python tensorflow实现mnist手写数字识别示例【非卷积与卷积实现】
Dec 19 #Python
You might like
php中使用session防止用户非法登录后台的方法
2015/01/27 PHP
PHP判断IP并转跳到相应城市分站的方法
2015/03/25 PHP
PHP简单实现上一页下一页功能示例
2016/09/14 PHP
PHP实现QQ快速登录的方法
2016/09/28 PHP
laravel 解决强制跳转 https的问题
2019/10/22 PHP
js setTimeout 参数传递使用介绍
2013/08/13 Javascript
JS两种定义方式的区别、内部原理
2013/11/21 Javascript
Javascript高级技巧分享
2014/02/25 Javascript
Javascript中数组sort和reverse用法分析
2014/12/30 Javascript
如何使用HTML5地理位置定位功能
2015/04/27 Javascript
js实现模拟计算器退格键删除文字效果的方法
2015/05/07 Javascript
javascript实现checkbox复选框实例代码
2016/01/10 Javascript
JQuery 传送中文乱码问题的简单解决办法
2016/05/24 Javascript
JavaScript+Java实现HTML页面转为PDF文件保存的方法
2016/05/30 Javascript
AngularJS 作用域详解及示例代码
2016/08/17 Javascript
js模式化窗口问题![window.dialogArguments]
2016/10/30 Javascript
JavaScript实现多栏目切换效果
2016/12/12 Javascript
node.js实现带进度条的多文件上传
2020/03/27 Javascript
解决node.js含有%百分号时发送get请求时浏览器地址自动编码的问题
2019/11/20 Javascript
深入了解JS之作用域和闭包
2020/06/16 Javascript
解决vue的touchStart事件及click事件冲突问题
2020/07/21 Javascript
[02:50]【扭转乾坤,只此一招】DOTA2全新版本永雾林渊开启新篇章
2020/12/24 DOTA
python内存管理分析
2015/04/08 Python
Linux中安装Python的交互式解释器IPython的教程
2016/06/13 Python
linux下python中文乱码解决方案详解
2019/08/28 Python
使用Pycharm分段执行代码
2020/04/15 Python
Pandas把dataframe或series转换成list的方法
2020/06/14 Python
python开发一款翻译工具
2020/10/10 Python
CSS3 实现飘动的云朵动画
2020/12/01 HTML / CSS
HTML5 在canvas中绘制文本附效果图
2014/06/23 HTML / CSS
自我鉴定怎么写
2013/12/05 职场文书
商铺租赁意向书
2014/04/01 职场文书
供货协议书范本
2014/04/22 职场文书
好习惯伴我成长演讲稿
2014/05/21 职场文书
2015年幼儿教师个人工作总结
2015/05/20 职场文书
React 高阶组件HOC用法归纳
2021/06/13 Javascript