[英]Tensorflow ImportError on OS X
TL;DR getting ImportError: cannot import name pywrap_tensorflow
when trying to use TensorFlow on El Capitan. TL; DR得到
ImportError: cannot import name pywrap_tensorflow
尝试在El Capitan上使用TensorFlow时ImportError: cannot import name pywrap_tensorflow
。
Details: I followed the TensorFlow installation instructions for Mac OS X from here . 详细信息:我从这里开始按照Mac OS X的TensorFlow安装说明进行操作。
Mac OS X, CPU only, Python 2.7: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
These steps were successful. 这些步骤是成功的。
So let's try it: 因此,让我们尝试一下:
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
TL;DR: Don't run ipython
(or python
) from the root of the TensorFlow git repository when you want to import tensorflow
. TL; DR:要
import tensorflow
时,请勿从TensorFlow git存储库的根目录运行ipython
(或python
)。
I answered a similar question here . 我在这里回答了类似的问题。 The easiest solution is to
cd
out of the current directory (eg cd ~
) before running ipython
. 最简单的解决方法是
cd
出当前目录(例如cd ~
运行前ipython
。 This will prevent Python from being confused by the tensorflow
source subdirectory in the current path. 这将防止Python被当前路径中的
tensorflow
源子目录混淆。 The ./tensorflow
directory in the git repository doesn't contain all of the generated code (such as pywrap_tensorflow
) that is needed to run TensorFlow, but does contain a file called __init__.py
, and this confuses the Python interpreter. git存储库中的
./tensorflow
目录不包含运行TensorFlow所需的所有生成的代码(例如pywrap_tensorflow
),但确实包含一个名为__init__.py
的文件,这使Python解释器感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.