简体   繁体   中英

Tensorflow (CPU only) installation Error | Ubuntu 14.10 | numpy 1.8.2

I'm in the process of installing Tensorflow in my Ubuntu 14.10. I've previously installed numpy , scipy , sklearn and also ipython-notebook . I followed the official documentation at Tensorflow.org ( pip installation ).The location of my tensorflow installation directory is /usr/local/lib/python2.7/dist-packages . I'm getting following error when I execute import tensorflow as ts in my Ubuntu terminal.

>>> 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 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  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


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter from there.

According to the error, it has to be with numpy. I tried to upgrade numpy using command sudo pip install --upgrade numpy but this doesn't seem to upgrade my existing numpy version and the problem still remains.

Any suggestions in solving this issue ?

As I mentioned in the description, I had previously installed numpy. For TensorFlow to run properly numpy has to be there. There has been two numpy versions in my machine.

When I typed

>> import numpy
>> print numpy.__version__

I got 1.8.something as my numpy version. According to the threads I read, this one is somewhat old and doesn't agree with Tensorflow, so I tried to upgrade the numpy version via

pip install numpy --upgrade

command. Still I got 1.8.* as my numpy version by executing above commands in python console. What I did next was to locate my numpy in python and removed numpy from there. These are the commands I used to locate and remove numpy.

numpy.__path__ #to locate numpy location/path

Then I exit from python console and executed following in Ubuntu terminal to remove numpy.

sudo rm -rf /path_to_numpy/numpy  #this removed numpy 1.8.* version 

Then I ran a sudo apt-get update command and checked the numpy version again and now python console reflected that I'm referring to the newer version of numpy ( 1.11.3 ).

The problem solved.

(I again encountered another issue while installing Tensorflow after successfully solving this issue. In that case I had to upgrade python six package)

Now Tensorflow works well in my Ubuntu 14.10 :)

Thanks for your concern :)

Did you follow the instructions?

please exit the tensorflow source tree, and relaunch your python interpreter from there.

I ran into the same problem on OS X (10.12). Like you, I got caught in a loop where two versions of python didn't match but reinstalling wasn't fixing the mismatch. Eventually, a more thorough removal and reinstallation worked:

  1. upgrade pip ( sudo pip install --upgrade pip )
  2. delete the ~/tensorflow directory and its contents
  3. reinstall virtualenv and activate it as per instructions
  4. create a virtualenv environment ( virtualenv --system-site-packages ~/tensorflow )
  5. reinstall tensorflow, using sudo to deal with a permissions issue
    ( sudo pip install --upgrade tensorflow )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM