Home > Blockchain >  When I import tensorflow, the output error `ImportError: numpy.core.multiarray failed to import`
When I import tensorflow, the output error `ImportError: numpy.core.multiarray failed to import`

Time:05-30

When I import tensorflow, the output error ImportError: numpy.core.multiarray failed to import

See below for details:

>>> 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.

CodePudding user response:

You need to reinstall numpy

  1. Check the numpy installation location
>>> import numpy
>>> print numpy.__path__
['/usr/lib64/python2.7/site-packages/numpy']

  1. delete directory
# rm -fr /usr/lib64/python2.7/site-packages/numpy
  1. re-install
# pip install numpy --upgrade --force

4.successfully import

>>> import tensorflow as tf
>>> 
  • Related