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实现sublime3的less编译插件示例
Apr 27 Python
跟老齐学Python之编写类之三子类
Oct 11 Python
python基础知识小结之集合
Nov 25 Python
Tensorflow实现卷积神经网络的详细代码
May 24 Python
Python多进程与服务器并发原理及用法实例分析
Aug 21 Python
Python正则表达式指南 推荐
Oct 09 Python
Python 通过调用接口获取公交信息的实例
Dec 17 Python
Django 内置权限扩展案例详解
Mar 04 Python
Python两个字典键同值相加的几种方法
Mar 05 Python
PIL对上传到Django的图片进行处理并保存的实例
Aug 07 Python
opencv设置采集视频分辨率方式
Dec 10 Python
在python中利用dict转json按输入顺序输出内容方式
Feb 27 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
磨咖啡豆的密诀
2021/03/03 冲泡冲煮
基于Swoole实现PHP与websocket聊天室
2016/08/03 PHP
PHP实现的redis主从数据库状态检测功能示例
2017/07/20 PHP
Laravel中如何轻松容易的输出完整的SQL语句
2020/07/26 PHP
jquery 注意事项与常用语法小结
2010/06/07 Javascript
常见表单重复提交问题整理及解决方法
2013/11/13 Javascript
node.js中的fs.realpathSync方法使用说明
2014/12/16 Javascript
JavaScript显示表单内元素数量的方法
2015/04/02 Javascript
js实现的早期滑动门菜单效果代码
2015/08/27 Javascript
关于动态生成dom绑定事件失效的原因及解决方法
2016/08/06 Javascript
深入理解javascript中concat方法
2016/12/12 Javascript
bootstrap modal弹出框的垂直居中
2016/12/14 Javascript
Bootstrap表单制作代码
2017/03/17 Javascript
QRCode.js:基于JQuery的生成二维码JS库的使用
2017/06/23 jQuery
js 概率计算(简单版)
2017/09/12 Javascript
JavaScript学习总结(一) ECMAScript、BOM、DOM(核心、浏览器对象模型与文档对象模型)
2018/01/07 Javascript
mpvue 如何使用腾讯视频插件的方法
2018/07/16 Javascript
javascript写一个ajax自动拦截并下载数据代码实例
2019/09/07 Javascript
JS实现公告上线滚动效果
2021/01/10 Javascript
[48:24]完美世界DOTA2联赛循环赛LBZS vs Forest 第一场 10月30日
2020/10/31 DOTA
numpy库与pandas库axis=0,axis= 1轴的用法详解
2019/05/27 Python
详解Python是如何实现issubclass的
2019/07/24 Python
python Django 反向访问器的外键冲突解决
2020/05/20 Python
如何使用python记录室友的抖音在线时间
2020/06/29 Python
Python3.8安装Pygame教程步骤详解
2020/08/14 Python
HTML5实现直播间评论滚动效果的代码
2020/05/27 HTML / CSS
拉夫劳伦爱尔兰官方网站:Ralph Lauren爱尔兰
2020/04/10 全球购物
SQL面试题
2013/04/30 面试题
小学生家长评语集锦
2014/01/30 职场文书
海飞丝广告词
2014/03/20 职场文书
医疗器械售后服务承诺书
2014/05/21 职场文书
法人授权委托书公证范本
2014/09/14 职场文书
党员剖析材料范文
2014/12/18 职场文书
个人自荐书范文
2015/03/09 职场文书
苦儿流浪记读书笔记
2015/07/01 职场文书
Java数组详细介绍及相关工具类
2022/04/14 Java/Android