2016-01-12 67 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] 
...