【问题标题】:Cannot import Tensorflow in ipython无法在 ipython 中导入 Tensorflow
【发布时间】:2017-03-08 22:40:59
【问题描述】:

我的 macbook pro Yosemite 上有 tensorflow 版本 1.0.0 非 GPU 版本。它安装在 virtualenv 中,我有 python 2.7。我有六个版本 1.4.1。当我在命令行上执行python 并导入六个时,它工作正常。但是当我输入 'ipython' 并导入 tensorflow 时,我看到了这个错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-1-cd232424f60d> in <module>()
----> 1 execfile('hw4/net.py')

/Users/lingxiao/Documents/research/dialogue-systems/hw4/net.py in <module>()
      8 import time
      9 import numpy as np
---> 10 import tensorflow as tf
     11 
     12 import app

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
     22 
     23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
     25 # pylint: enable=wildcard-import
     26 

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
    122 from tensorflow.python.platform import resource_loader
    123 from tensorflow.python.platform import sysconfig
--> 124 from tensorflow.python.platform import test
    125 
    126 from tensorflow.python.util.all_util import remove_undocumented

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/test.py in <module>()
     67 # pylint: disable=g-bad-import-order
     68 from tensorflow.python.client import device_lib as _device_lib
---> 69 from tensorflow.python.framework import test_util as _test_util
     70 from tensorflow.python.platform import googletest as _googletest
     71 from tensorflow.python.util.all_util import remove_undocumented

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/test_util.py in <module>()
     41 from tensorflow.python.framework import random_seed
     42 from tensorflow.python.framework import versions
---> 43 from tensorflow.python.platform import googletest
     44 from tensorflow.python.platform import tf_logging as logging
     45 from tensorflow.python.util import compat

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/googletest.py in <module>()
     31 
     32 from tensorflow.python.platform import app
---> 33 from tensorflow.python.platform import benchmark  # pylint: disable=unused-import
     34 
     35 Benchmark = benchmark.TensorFlowBenchmark  # pylint: disable=invalid-name

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/benchmark.py in <module>()
    115 
    116 
--> 117 class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
    118   """Abstract class that provides helper functions for running benchmarks.
    119 

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc in with_metaclass(meta, *bases)
    564 def with_metaclass(meta, *bases):
    565     """Create a base class with a metaclass."""
--> 566     return meta("NewBase", bases, {})
    567 
    568 def add_metaclass(metaclass):

/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/benchmark.py in __new__(mcs, clsname, base, attrs)
    110     newclass = super(mcs, _BenchmarkRegistrar).__new__(
    111         mcs, clsname, base, attrs)
--> 112     if not newclass.is_abstract():
    113       GLOBAL_BENCHMARK_REGISTRY.add(newclass)
    114     return newclass

AttributeError: type object 'NewBase' has no attribute 'is_abstract'

我尝试升级六,但我仍然看到版本 1.4.1。六是这里的问题吗?如果不是,那是什么?

【问题讨论】:

  • 从这里我无法判断错误是什么:错误消息是什么。
  • 这只是错误信息的一部分。它突然中断。
  • 抱歉各位更新了帖子。
  • 你用的是哪六个版本?我有一个类似的环境,我在六个==1.10.0,tensorflow==1.0.0,Python 2.7.12
  • @ruohoruotsi ruotsi 如果您发布您所说的作为答案,我可以检查为您解决。

标签: python tensorflow ipython six


【解决方案1】:

似乎有很多事情纠缠在一起。我将 Anaconda2 与 six==1.10.0、tensorflow==1.0.0 和 Python 2.7.12 一起使用。一个快速的实验是安装 Anaconda2(即使用 python2.7),然后安装 pip install TF 和其他依赖项并尝试一下。

Anaconda 安装是独立的,因此您不会受到其他系统范围问题的影响。我只是通过运行/Users/myusername/anaconda2/bin/ipython 来做到这一点的

【讨论】:

    【解决方案2】:

    我的猜测是您需要从虚拟环境中安装 iPython。如果您还没有这样做,即使您在虚拟环境中,ipython 也会使用原版解释器。

    【讨论】:

    • 当我尝试在我的 virtualenv 中 pip install ipython 时,它说要求已经满足?
    • 您是如何创建和激活虚拟环境的? “which ipython”和“which pip”的输出是什么?当您在虚拟环境之外时,这些命令的输出是什么?
    • 我做了source ~/tensorflow/bin/activate,其中ipython在/usr/local/bin/ipython,其中pip是/Users/lingxiao/tensorflow/bin/pip。在虚拟环境之外,ipython 位于 /usr/local/bin/ipython,pip 位于 /usr/local/bin/pip
    • which ipython 还应该返回虚拟环境中的路径,类似于 pip。我会尝试从虚拟环境中卸载并重新安装 ipython。如果这不起作用,那么可能是时候摆脱虚拟环境并创建一个新环境了。
    • 这很有趣,因为环境中的哪个 ipython 没有从内部返回路径,它位于 usr/local/bin/ipython。当我尝试从 virtualenv 中卸载它时,我得到 Not uninstalling ipython at /Library/Python/2.7/site-packages, outside environment /Users/lingxiao/tensorflow
    猜你喜欢
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多