TensorFlow导入错误:没有名为_pywrap_tensorflow的模块

时间:2016-12-07 02:39:01

标签: python tensorflow

我试图在TensorFlow install docs之后在Mac上设置TensorFlow。

但是,在完成概述的步骤并尝试" import tensorflow as tf"后,我收到以下错误跟踪:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 21, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow')
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _pywrap_tensorflow

我之前已经在我的机器上安装并使用过TensorFlow,从未遇到过这个问题。

1 个答案:

答案 0 :(得分:2)

这部分看起来不对:

File "/usr/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow')
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

它使用来自pywrap_tensorflow的Python安装中的/usr/local/lib/python2.7,但使用来自importlib的{​​{1}}。{/ p>

您的Python包搜索路径一定有问题。参见例如Keras import error Nadam有关问题排查提示。