我是初学者,我尝试按照网站上的说明在Macbook上安装张量流。
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
>>>
我是python的新手,我在互联网上尝试了一些解决方案,但到目前为止还没有一个解决方案。也许错误是由于pip安装造成的。我被困在这2天了。谢谢你的帮助!
答案 0 :(得分:2)
要添加到上一个答案 - 在我的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 /中的那个。
作为临时解决方案,我刚刚将numpy
中的/System/Library
文件夹重命名为numpy.old
。在此之后正确导入Tensorflow
。
答案 1 :(得分: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
答案 2 :(得分:0)
所以最后我做的是删除了tensorflow,pip和一切。问题是我使用Mac OSX python因为我遇到了问题。我使用自制软件安装python,然后创建virtualenv并使用pip再次安装tensorflow。之后就开始了。
答案 3 :(得分:0)
这解决了我的问题:
$ sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
环境和症状
我在Mac OS X Yosemite上安装了3个pythons:
当然,我在设置正确的方面表现不佳,并且python二进制文件和库都在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.
<强>解决方案强>
在查看 se7en007 对https://github.com/tensorflow/tensorflow/issues/559的评论后,我运行了这些喜欢我的问题的命令。请参阅numpy
命令之前和之后的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]
...