MacにTensorFlowを入れようとしたら、Numpyのエラーが出たのでメモ
自分のMac (Mavericks 10.9.5) を入れようとしたら、Numpyのエラーが出て詰まったのでメモ。
TensorFlowは、公式サイトの以下の手順でインストール
[https://www.tensorflow.org/versions/master/get_started/os_setup.html#pip-installation] sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
上記で、問題なくインストールできたものの、以下のエラーが出てimportできず。
$ python >>> import tensorflow (中略) Error: numpy.core.multiarray failed to import
ググッて調べて見ると、System PythonにTensorFlowを入れると、別PATHのNumpyを読んでしまうためにエラーが出るという情報あり。
https://groups.google.com/a/tensorflow.org/forum/#!topic/discuss/O4JQjcyI-9M
In my case (using mac OS) reinstalling numpy version 1.10 with pip was not enough because pip installs in /Library/Python/2.7/site-packages> I had numpy 1.6 simultaneously in a different location /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python When importing tensorflow this was the location first sought for numpy (you can check that with sys.path). Solution: I had to manually remove numpy from this other location not used by pip with "sudo rm .r numpy". Then just restart python.
ここに書かれていた情報を参考に「/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python」以下を見てみたところ、こちらにも過去に入れたと思われるNumpyのファイルがあったので、とりあえずリネームして動作確認
cd /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ sudo mv numpy/ numpy_old $ python >>> import tensorflow
こちらで問題なく動いた様子。
以下はエラーログをググった際に引っ掛けるようのエラーログ全文。
>>> import tensorflow as tf RuntimeError: module compiled against API version 9 but this version of numpy is 6 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 23, in <module> from tensorflow.python import * File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module> from tensorflow import contrib File "/Library/Python/2.7/site-packages/tensorflow/contrib/__init__.py", line 23, in <module> from tensorflow.contrib import layers File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/__init__.py", line 68, in <module> from tensorflow.contrib.layers.python.layers import * File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/__init__.py", line 22, in <module> from tensorflow.contrib.layers.python.layers.initializers import * File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/initializers.py", line 24, in <module> from tensorflow.python.ops import random_ops File "/Library/Python/2.7/site-packages/tensorflow/python/ops/random_ops.py", line 23, in <module> from tensorflow.python.framework import ops File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 39, in <module> from tensorflow.python.framework import versions File "/Library/Python/2.7/site-packages/tensorflow/python/framework/versions.py", line 22, in <module> from tensorflow.python import pywrap_tensorflow File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module> _pywrap_tensorflow = swig_import_helper() File "/Library/Python/2.7/site-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