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

yipeiwu_com5年前Python基础

在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帮你微信头像任意添加装饰别再@微信官方了

Python帮你微信头像任意添加装饰别再@微信官方了

@微信官方 昨天朋友圈刷爆了@微信官方的梗,从起初的为头像添加国旗,到最后的各种Book思议的需求…而我呢?@了辣么辣么多的奥特曼,结果还是加班到12点多…最后想想,人还是得靠...

python中的插值 scipy-interp的实现代码

python中的插值 scipy-interp的实现代码

具体代码如下所示: import numpy as np from matplotlib import pyplot as plt from scipy.interpolate im...

python中的迭代和可迭代对象代码示例

什么是迭代(iteration)呢? 给定一个list或者tuple,通过for循环来遍历这个list或者tuple、这种遍历就是迭代(iteration)。只要是可迭代的对象都可以进行...

Python 依赖库太多了该如何管理

Python 依赖库太多了该如何管理

在 Python 的项目中,如何管理所用的全部依赖库呢?最主流的做法是维护一份“requirements.txt”,记录下依赖库的名字及其版本号。 那么,如何来生成这份文件呢?在上篇文章...

Python读取Json字典写入Excel表格的方法

Python读取Json字典写入Excel表格的方法

需求: 因需要将一json文件中大量的信息填入一固定格式的Excel表格,单纯的复制粘贴肯定也能完成,但是想偷懒一下,于是借助Python解决问题。 环境: Windows7 +Pyth...