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抓取网页中的图片示例
Feb 28 Python
利用 Monkey 命令操作屏幕快速滑动
Dec 07 Python
Python使用正则表达式抓取网页图片的方法示例
Apr 21 Python
基于Python3 逗号代码 和 字符图网格(详谈)
Jun 22 Python
Python模拟随机游走图形效果示例
Feb 06 Python
tensorflow 打印内存中的变量方法
Jul 30 Python
Python 读取WAV音频文件 画频谱的实例
Mar 14 Python
python 字符串格式化的示例
Sep 21 Python
如何使用pycharm连接Databricks的步骤详解
Sep 23 Python
python 对象真假值的实例(哪些视为False)
Dec 11 Python
使用python tkinter开发一个爬取B站直播弹幕工具的实现代码
Feb 07 Python
Python数据可视化之Seaborn的安装及使用
Apr 19 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 checkbox复选框值的获取与checkbox默认值输出方法
2010/05/15 PHP
用php随机生成福彩双色球号码的2种方法
2013/02/04 PHP
php中让上传的文件大小在上传前就受限制的两种解决方法
2013/06/24 PHP
PHP中上传多个文件的表单设计例子
2014/11/19 PHP
thinkphp微信开之安全模式消息加密解密不成功的解决办法
2015/12/02 PHP
php写app用的框架整理
2019/09/29 PHP
一个JavaScript继承的实现
2006/10/24 Javascript
extJs 文本框后面加上说明文字+下拉列表选中值后触发事件
2009/11/27 Javascript
两个比较有用的Javascript工具函数代码
2010/02/17 Javascript
javascript 循环读取JSON数据的代码
2010/07/17 Javascript
JavaScript获取文本框内选中文本的方法
2015/02/20 Javascript
jQuery实现多级下拉菜单jDropMenu的方法
2015/08/28 Javascript
jquery实现点击其他区域时隐藏下拉div和遮罩层的方法
2015/12/23 Javascript
JavaScript读二进制文件并用ajax传输二进制流的方法
2016/07/18 Javascript
详解React Native网络请求fetch简单封装
2017/08/10 Javascript
史上最全JavaScript常用的简写技巧(推荐)
2017/08/17 Javascript
通过JS运行机制的角度说说作用域
2019/03/12 Javascript
优雅的处理vue项目异常实战记录
2019/06/05 Javascript
JavaScript解析JSON数据示例
2019/07/16 Javascript
layui树形菜单动态遍历的例子
2019/09/23 Javascript
Vue+Element-U实现分页显示效果
2020/11/15 Javascript
Python的math模块中的常用数学函数整理
2016/02/04 Python
Python数据结构与算法之图的广度优先与深度优先搜索算法示例
2017/12/14 Python
浅析Python数据处理
2018/05/02 Python
Python常驻任务实现接收外界参数代码解析
2020/07/21 Python
Python字符串函数strip()原理及用法详解
2020/07/23 Python
python3让print输出不换行的方法
2020/08/24 Python
Sneaker Studio乌克兰:购买运动鞋
2018/03/26 全球购物
香港百佳网上超级市场:PARKNSHOP.com
2020/06/10 全球购物
幼儿园中班开学寄语
2014/04/03 职场文书
计算机相关专业自荐信
2014/07/02 职场文书
市级三好学生事迹材料
2014/08/27 职场文书
试用期转正后的自我评价
2014/09/21 职场文书
房屋维修申请报告
2015/05/18 职场文书
TensorFlow的自动求导原理分析
2021/05/26 Python
Redis 持久化 RDB 与 AOF的执行过程
2021/11/07 Redis