2016-01-12 99 views
3

我是一名初學者,我嘗試按照網站上給出的說明在Macbook上安裝張量流。Tensorflow未正確安裝

sudo easy_install pip 
sudo easy_install --upgrade six 
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl 

安裝後,當我試圖導入張流,我收到以下錯誤:

>>> import tensorflow 
RuntimeError: module compiled against API version a but this version of numpy is 9 
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 50, in <module> 
    from tensorflow.python.framework.framework_lib import * 
    File "/Library/Python/2.7/site-packages/tensorflow/python/framework/framework_lib.py", line 62, in <module> 
    from tensorflow.python.framework.ops import Graph 
    File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 40, in <module> 
    from tensorflow.python.framework import versions 
    File "/Library/Python/2.7/site-packages/tensorflow/python/framework/versions.py", line 24, 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 
>>> 

我是新來的蟒蛇,我已經嘗試過互聯網,但沒有對幾個解決方案他們迄今爲止工作。也許錯誤是由於點安裝。自2天以來我就陷入了這個問題。感謝幫助!

+0

試過'sudo pip install -U numpy'? – alvas

+0

是的,它顯示Requirement已經是最新的:numpy in /Library/Python/2.7/site-packages –

+0

你是否試過'sudo pip install numpy == 1.10.4'來獲取最新版本?還有一個標誌點,' - 升級'這可能有所幫助。 –

回答

0

所以最後我所做的是去除了tensorflow,點子和一切。問題是我正在使用Mac OSX python,因爲我遇到了問題。我用自制軟件安裝python,然後創建virtualenv並使用pip重新安裝tensorflow。之後,它正在工作。

1

我想我遇到了同樣的問題。這是由Max OSX上工廠安裝的Python的早期版本的工廠包含的numpy引起的。

我試過sudo pip uninstall numpy並且因子包含的numpy依然存在。爲了解決這個問題,我升級使用easy_install工廠包括numpy的,然後用pip安裝tensorflow和它的工作:

sudo easy_install -U numpy 
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl 
1

要添加到以前的答案 - 我OSX機(10.11)上,我發現了兩個工廠安裝numpy - 一個在/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy,另一個在/Library/Python/2.7/site-packages/numpy/。據我所知,pip將升級/ Library中的一個,但python不斷嘗試使用/ System/Library/first中的一個。

作爲臨時解決方案,我只是將numpy文件夾重命名爲/System/Librarynumpy.old。之後正確導入Tensorflow

0

摘要

這解決了我的問題:

$ sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy 

詳細

環境和症狀

我已經安裝在我的Mac OS X的優勝美地3條蟒蛇:

    把隨我已經安裝了,我已經安裝了
  • 3.4 OS
  • 2.7
  • 2.6

當然,我沒有在正確設置事情做得不好和蟒蛇的二進制文件和庫遍佈在Mac上的地方。

我試圖與https://github.com/Ning-Ding/Implementation-CVPR2015-CNN-for-ReID/tree/master/CUHK03

$ python ./main.py --dataset cuhk-03.h5 

Using TensorFlow backend. 
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9 
Traceback (most recent call last): 
    File "./main.py", line 14, in <module> 
    from model import generate_model,compile_model 
    File "/Users/rv186016/repositories/Implementation-CVPR2015-CNN-for-ReID/CUHK03/model.py", line 12, in <module> 
    from keras.layers import Input 
    File "/Library/Python/2.7/site-packages/keras/__init__.py", line 3, in <module> 
    from . import activations 
    File "/Library/Python/2.7/site-packages/keras/activations.py", line 4, in <module> 
    from . import backend as K 
    File "/Library/Python/2.7/site-packages/keras/backend/__init__.py", line 73, in <module> 
    from .tensorflow_backend import * 
    File "/Library/Python/2.7/site-packages/keras/backend/tensorflow_backend.py", line 1, in <module> 
    import tensorflow as tf 
    File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 24, in <module> 
    from tensorflow.python import * 
    File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module> 
    from tensorflow.python import pywrap_tensorflow 
    File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module> 
    raise ImportError(msg) 
ImportError: Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module> 
    from tensorflow.python.pywrap_tensorflow_internal import * 
    File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module> 
    _pywrap_tensorflow_internal = swig_import_helper() 
    File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper 
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) 
ImportError: numpy.core.multiarray failed to import 


Failed to load the native TensorFlow runtime. 

See https://www.tensorflow.org/install/install_sources#common_installation_problems 

for some common reasons and solutions. Include the entire stack trace 
above this error message when asking for help. 

解決方案

上下工夫https://github.com/tensorflow/tensorflow/issues/559看着se7en007的評論後,當這個錯誤,我跑這些命令其愛我的問題。請參閱numpy版本中的diff和rm命令前後的路徑。

$ python 
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import numpy 
>>> numpy.__version__ 
'1.8.0rc1' 
>>> numpy.__path__ 
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy'] 
>>> exit() 

$ sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy 
MUSRV186016-382:CUHK03 rv186016$ python 
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import numpy 
>>> numpy.__path__ 
['/Library/Python/2.7/site-packages/numpy'] 
>>> numpy.__version__ 
'1.12.0' 
>>> ^D 

$ python ./main.py --dataset cuhk-03.h5 
Using TensorFlow backend. 
____________________________________________________________________________________________________ 
Layer (type)      Output Shape   Param #  Connected to 
==================================================================================================== 
input_1 (InputLayer)    (None, 160, 60, 3) 0 
____________________________________________________________________________________________________ 
input_2 (InputLayer)    (None, 160, 60, 3) 0 
____________________________________________________________________________________________________ 
conv2d_1 (Conv2D)    (None, 156, 56, 20) 1520  input_1[0][0] 
                    input_2[0][0] 
...