【问题标题】:Tensorflow ImportError on OS XOS X 上的 TensorFlow 导入错误
【发布时间】:2016-06-15 06:05:18
【问题描述】:

TL;DR 在尝试在 El Capitan 上使用 TensorFlow 时收到 ImportError: cannot import name pywrap_tensorflow

详细信息:我按照here 的 Mac OS X 的 TensorFlow 安装说明进行操作。

Mac OS X,仅 CPU,Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py2-none-any.whl

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

$ sudo pip install --upgrade $TF_BINARY_URL

这些步骤是成功的。

那么让我们试试吧:

22:54:00/tensorflow $ipython
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | File not found: '/shared/.pythonstartup'

In [1]: import tensorflow as tf
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf

/git/tensorflow/tensorflow/__init__.py in <module>()
     21 from __future__ import print_function
     22
---> 23 from tensorflow.python import *

/git/tensorflow/tensorflow/python/__init__.py in <module>()
     46 _default_dlopen_flags = sys.getdlopenflags()
     47 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 48 from tensorflow.python import pywrap_tensorflow
     49 sys.setdlopenflags(_default_dlopen_flags)
     50

ImportError: cannot import name pywrap_tensorflow

【问题讨论】:

标签: python macos tensorflow


【解决方案1】:

TL;DR:当您想要 import tensorflow 时,不要从 TensorFlow git 存储库的根目录运行 ipython(或 python)。

我回答了一个类似的问题here。最简单的解决方案是在运行ipython 之前将cd 移出当前目录(例如cd ~)。这将防止 Python 被当前路径中的 tensorflow 源子目录混淆。 git 存储库中的 ./tensorflow 目录不包含运行 TensorFlow 所需的所有生成代码(例如 pywrap_tensorflow),但包含一个名为 __init__.py 的文件,这会使 Python 解释器感到困惑。

【讨论】:

  • 啊,你是对的。这是一个奇怪的错误,我不记得了。
  • 非常适合我。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-03-22
  • 2017-08-30
  • 1970-01-01
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 2018-01-13
  • 2016-08-28
相关资源
最近更新 更多