ImportError: numpy.core.multiarray failed to import解决办法

描述问题

ImportError: numpy.core.multiarray failed to import

>>> import tensorflow as tf
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x7
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/lib/python2.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.

在这里插入图片描述

解决办法

  • 查看 numpy安装位置
>>> import numpy
>>> print numpy.__path__
['/usr/lib64/python2.7/site-packages/numpy']
  • 删除目录
# rm -fr /usr/lib64/python2.7/site-packages/numpy
  • 再重新安装
# pip install numpy --upgrade --force
  • 问题解决
>>> import tensorflow as tf
>>>

在这里插入图片描述