导入tensorflow时出现numpy版本错误

时间:2016-10-07 02:35:09

标签: python python-2.7 numpy runtime-error tensorflow

我已经为tensorflow执行了pip install

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

import tensorflow as tf

我遇到了以下错误:

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

我已使用numpy检查了我的print numpy.__version__版本。它显示"1.8.2"。那么,我现在该怎么办?谢谢!

1 个答案:

答案 0 :(得分:2)

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

一旦你有了anaconda,那就做:

conda install -c conda-forge tensorflow
相关问题