解决Tensorflow安装成功,但在导入时报错的问题


Posted in Python onJune 13, 2018

在Mac上按照官网教程安装成功tensor flow后,但在程序中导入时,仍然报错,包括但不限于以下两个错误。对于这种错误,原因主要在于Mac内默认的python库比较老了,即便通过pip命令安装了新的包,python也会默认导入默认位置的包。这时候需要做的就是删除,有冲突的包,对于以下两个错误,就是分别时numpy和six两个包冲突了。

可以在python命令行环境下,通过numpy.version和six.version两个命令查看当前版本,如果与预期的不一致,就可以删掉。

可以通过numpy.path查看默认包的位置。

删掉即可

import tensorflow
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9 
Traceback (most recent call last): 
File “”, line 1, in 
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in 
from tensorflow.python import * 
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 49, in 
from tensorflow.python import pywrap_tensorflow 
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 52, in 
raise ImportError(msg) 
ImportError: Traceback (most recent call last): 
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 41, in 
from tensorflow.python.pywrap_tensorflow_internal import * 
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 28, in 
_pywrap_tensorflow_internal = swig_import_helper() 
File “/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 24, in swig_import_helper 
_mod = imp.load_module(‘_pywrap_tensorflow_internal', fp, pathname, description) 
ImportError: numpy.core.multiarray failed to import 
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.

Traceback (most recent call last): 
File “”, line 1, in 
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in 
from tensorflow.python import * 
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 104, in 
from tensorflow.python.platform import test 
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/test.py”, line 41, in 
from tensorflow.python.framework import test_util as _test_util 
File “/Library/Python/2.7/site-packages/tensorflow/python/framework/test_util.py”, line 54, in 
from tensorflow.python.platform import googletest 
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/googletest.py”, line 35, in 
from tensorflow.python.platform import benchmark 
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”, line 120, in 
class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)): 
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py”, line 566, in with_metaclass 
return meta(“NewBase”, bases, {}) 
File “/Library/Python/2.7/site-packages/tensorflow/python/platform/benchmark.py”, line 115, in new 
if not newclass.is_abstract(): 
AttributeError: type object ‘NewBase' has no attribute ‘is_abstract' 
import tensorflow 
Traceback (most recent call last): 
File “”, line 1, in 
File “/Library/Python/2.7/site-packages/tensorflow/init.py”, line 24, in 
from tensorflow.python import * 
File “/Library/Python/2.7/site-packages/tensorflow/python/init.py”, line 49, in 
from tensorflow.python import pywrap_tensorflow 
ImportError: cannot import name pywrap_tensorflow

以上这篇解决Tensorflow安装成功,但在导入时报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中dictionary items()系列函数的用法实例
Aug 21 Python
Python定时执行之Timer用法示例
May 27 Python
Python爬虫爬取一个网页上的图片地址实例代码
Jan 16 Python
python+matplotlib实现动态绘制图片实例代码(交互式绘图)
Jan 20 Python
pandas每次多Sheet写入文件的方法
Dec 10 Python
python对于requests的封装方法详解
Jan 03 Python
Python中三元表达式的几种写法介绍
Mar 04 Python
Python视频编辑库MoviePy的使用
Apr 01 Python
python实现程序重启和系统重启方式
Apr 16 Python
实现Python3数组旋转的3种算法实例
Sep 16 Python
python 获取字典特定值对应的键的实现
Sep 29 Python
Python中过滤字符串列表的方法
Dec 22 Python
基于pip install django失败时的解决方法
Jun 12 #Python
基于Python pip用国内镜像下载的方法
Jun 12 #Python
pip安装时ReadTimeoutError的解决方法
Jun 12 #Python
解决pip install的时候报错timed out的问题
Jun 12 #Python
pip install urllib2不能安装的解决方法
Jun 12 #Python
ubuntu17.4下为python和python3装上pip的方法
Jun 12 #Python
Python2.7.10以上pip更新及其他包的安装教程
Jun 12 #Python
You might like
php在线代理转向代码
2012/05/05 PHP
使用 PHPMAILER 发送邮件实例应用
2012/11/07 PHP
WordPress过滤垃圾评论的几种主要方法小结
2016/07/11 PHP
10个值得深思的PHP面试题
2016/11/14 PHP
基于Jquery的动态添加控件并取值的实现代码
2010/09/24 Javascript
js函数模拟显示桌面.scf程序示例
2014/04/20 Javascript
在JavaScript中操作时间之getUTCDate()方法的使用
2015/06/10 Javascript
javascript跨域方法、原理以及出现问题解决方法(详解)
2015/08/06 Javascript
jQuery实现验证年龄简单思路
2016/02/24 Javascript
论JavaScript模块化编程
2016/03/07 Javascript
js自制图片放大镜功能
2017/01/24 Javascript
微信小程序实现获取自己所处位置的经纬度坐标功能示例
2017/11/30 Javascript
Web安全之XSS攻击与防御小结
2018/12/13 Javascript
[00:43]魔廷新尊——痛苦女王至宝捆绑包
2020/06/12 DOTA
python求素数示例分享
2014/02/16 Python
python验证码识别实例代码
2018/02/03 Python
Python实现爬虫从网络上下载文档的实例代码
2018/06/13 Python
python如果快速判断数字奇数偶数
2019/11/13 Python
Python视频编辑库MoviePy的使用
2020/04/01 Python
css3让div随鼠标移动而抖动起来
2014/02/10 HTML / CSS
css3旋转木马_动力节点Java学院整理
2017/07/12 HTML / CSS
帕克纽约:PARKER NY
2018/12/09 全球购物
会话Bean的种类
2013/11/07 面试题
致全体运动员广播稿
2014/02/01 职场文书
广告业务员岗位职责
2014/02/06 职场文书
美容院营销方案
2014/03/05 职场文书
2015年元旦文艺汇演主持词
2014/03/26 职场文书
《神奇的克隆》教学反思
2014/04/10 职场文书
党员目标管理责任书
2014/07/25 职场文书
2014年房地产销售工作总结
2014/12/01 职场文书
先进个人总结范文
2015/02/15 职场文书
2015学校年度工作总结
2015/05/11 职场文书
社区安置帮教工作总结2015
2015/05/20 职场文书
歌剧魅影观后感
2015/06/05 职场文书
Nginx设置HTTPS的方法步骤 443证书配置方法
2022/03/21 Servers
Go语言编译原理之源码调试
2022/08/05 Golang