当前位置: 代码迷 >> python >> 由于Numpy错误而无法使用tensorflow
  详细解决方案

由于Numpy错误而无法使用tensorflow

热度:76   发布时间:2023-07-14 08:44:10.0

我正在运行Mac OS X Yosemite-10.10.5,我正在尝试在Python 2.7.10中运行tensorflow。 当我尝试导入tensorflow时出现此错误,我相信是由于未更新Numpy引起的:

$ 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 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 "/Users/krishnachatpar/Library/Python/2.7/lib/python/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Users/krishnachatpar/Library/Python/2.7/lib/python/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/krishnachatpar/Library/Python/2.7/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/krishnachatpar/Library/Python/2.7/lib/python/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/krishnachatpar/Library/Python/2.7/lib/python/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/krishnachatpar/Library/Python/2.7/lib/python/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

更新:当我尝试更新numpy时:

$ pip install numpy --upgrade
Collecting numpy
Using cachedhttp://files.pythonhosted.org/packages/e7/c1/d5c47de35e366b1c2f60da88a24b25d3037b892417c5c3c5398313fb54f5/numpy-1.15.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
tensorflow 1.1.0 has requirement six>=1.10.0, but you'll have six 1.4.1 which is incompatible.
Installing collected packages: numpy
Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

您必须将numpy升级到最新版本:

pip install numpy --upgrade

所以我想通了:

我切换到python3,安装了numpy和tensorflow:

Tensorflow install command:
python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
Collecting tensorflow==0.12.0 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

并在Python和numpy和tensorflow中都进行了测试。