导入 tensorflow 时出现 numpy 版本错误

Rea*_*Not 5 python runtime-error numpy python-2.7 tensorflow

我已经pip install为 tensorflow执行了。

在python命令行环境下,当我尝试

import tensorflow as tf
Run Code Online (Sandbox Code Playgroud)

我遇到了以下错误:

RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
Run Code Online (Sandbox Code Playgroud)

我已经numpy使用print numpy.__version__. 它显示"1.8.2"。那么,我现在该怎么办?谢谢!

kma*_*o23 2

从错误来看,您似乎正在运行 python 2.7 usr/local/binnumpy您的版本和安装之间存在不匹配问题tensorflow。我建议您安装 anaconda,因为它将确保正确的版本与您安装的版本tensorflow兼容。numpy

一旦你有了 anaconda,然后执行以下操作:

conda install -c conda-forge tensorflow
Run Code Online (Sandbox Code Playgroud)