5

I have executed pip install for tensorflow.

Under the python command line environment, when I tried

import tensorflow as tf

I met the following errors:

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

I have checked my numpy version using print numpy.__version__. It showed "1.8.2". So, what should I do now? Thanks!

kfb
  • 6,252
  • 6
  • 40
  • 51
ReadyOrNot
  • 81
  • 1
  • 3

1 Answers1

2

From the error, it looks like you're running python 2.7 from usr/local/bin. There is a mismatch problem between your numpy version and tensorflow installation. I'd recommend you to install anaconda since it will make sure that correct version of tensorflow that is compatible with your numpy version be installed.

Once you have anaconda, then do:

conda install -c conda-forge tensorflow
kmario23
  • 57,311
  • 13
  • 161
  • 150
  • 1
    Thanks a lot for your suggestion! Before I read your suggestion, I tried another way, that is to compile TensorFlow from source in my environment. It works fine now. – ReadyOrNot Oct 09 '16 at 03:23
  • @ReadyOrNot No problem, it's still less hassle to use anaconda distribution! – kmario23 Oct 09 '16 at 18:44
  • @ReadyOrNot I did the same you did, i.e., compiled tensorflow from source and created an env. Now even after I did a conda install tensorflow, it still going to the old tensorflow env: File "", line 1, in File "D:\Anaconda3\envs\tensorflow\Lib\site-packages\tensorflow\__init__.py", line 24, in from tensorflow.python import * – Prana Aug 19 '17 at 04:29
  • Ok. I think I solved it by deleting the tensorflow folder from the env. – Prana Aug 19 '17 at 04:39