【问题标题】:Import tensorflow error on macmac上导入tensorflow错误
【发布时间】:2017-09-27 10:03:42
【问题描述】:

环境

Mac OSX 10.10

Python:2.7.10

我在尝试import tensorflow时出现以下错误

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
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 "/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 48, 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

我在关注official install pege,并输入了这两个命令

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py2-none-any.whl

$ sudo pip install --upgrade $TF_BINARY_URL

我试过卸载tensorflowprotobuf,然后重新安装tensorflow,但还是报了同样的错误。

更新

卸载numpytensorflow后,我重新安装numpy。但是,我无法重新安装tensorflow

它扔了这个

$sudo  pip install --upgrade $TF_BINARY_URL
The directory '/Users/Coda/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/Coda/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You must give at least one requirement to install (see "pip help install")

是因为我错误地卸载了tensorflow吗? 我用pip uninstall tensorflow卸载。

【问题讨论】:

  • 当您尝试import numpy 时会发生什么?
  • 我可以完美导入numpy
  • 您可能使用了错误版本的 TensorFlow。
  • 我不确定需要安装哪个版本,但我安装了tensorflow 0.9.0
  • 最后,我安装了virtualenv,它成功了。但我还是想弄清楚这个问题。

标签: python python-2.7 tensorflow


【解决方案1】:

我认为问题在于您的numpy 比需要的版本旧一个(0x9 = 9;0xa = 10)。也许升级 numpy 并查看导入 tensorflow 之后是否有效。

编辑/更新:对于您的新错误,请尝试使用 --no-cache-dir 选项进行 pip 安装。

【讨论】:

  • 谢谢,但我遇到了新的问题,我已经更新了问题。
  • 我做到了,可以正常安装,但是还是不能导入tensorflow,报同样的错误,我的numpy的版本现在是1.8.0rc1
  • 有人解决了这个问题吗?我也真的需要帮助解决这个问题!谢谢!
  • 我从 pip(没有二进制 URL 选项)和最新的 numpy(Mac OS 10.12)安装了常规的 tensorflow。 TensorFlow 版本是 1.0.0,numpy 是 1.12.0。
猜你喜欢
  • 2016-08-28
  • 2017-08-30
  • 1970-01-01
  • 2018-03-11
  • 2016-10-28
  • 2018-01-13
  • 1970-01-01
  • 2019-01-16
  • 2016-02-17
相关资源
最近更新 更多