2017-10-20 132 views
0

我一直在學習tensorflow,直到現在一切都很好。我甚至用GPU來做一些tensorflow的計算。AttributeError:'NoneType'對象在張量流中沒有屬性'modules'

Traceback (most recent call last): 

    File "<ipython-input-6-41389fad42b5>", line 1, in <module> 
    import tensorflow as tf 

    File "/home/diego/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module> 
    from tensorflow.python import * 

    File "/home/diego/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module> 
    from tensorflow.python import pywrap_tensorflow 

ImportError: cannot import name pywrap_tensorflow 

這是很容易解決的,我只是重置控制檯:可是突然運行進口tensorflow時爲TF命令我有以下錯誤。但它非常不好,因爲我在每次運行腳本後都需要重置控制檯。 (即使腳本只是「進口tensorflow爲TF」

當我運行與F5整個腳本我有一個不同的錯誤,即使是唯一的命令是進口tensorflow爲TF。 我正在使用spyder 2.7 Python 2.7.12在Ubuntu 16.04.3 LTS上運行腳本。

File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile 
     execfile(filename, namespace) 

    File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile 
     builtins.execfile(filename, *where) 

    File "/home/diego/Desktop/Diego/Trial-Job/Code/pointnet/test2tf.py", line 7, in <module> 
     import tensorflow as tf 

    File "/home/diego/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module> 
     from tensorflow.python import * 

    File "/home/diego/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module> 
     from tensorflow.core.framework.graph_pb2 import * 

    File "/home/diego/.local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module> 
     from google.protobuf import descriptor as _descriptor 

    File "/home/diego/.local/lib/python2.7/site-packages/google/protobuf/__init__.py", line 37, in <module> 
     __import__('pkg_resources').declare_namespace(__name__) 

    File "/home/diego/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 50, in <module> 
     from pkg_resources.extern import six 

    File "/home/diego/.local/lib/python2.7/site-packages/pkg_resources/extern/__init__.py", line 44, in load_module 
     mod = sys.modules[extant] 

    AttributeError: 'NoneType' object has no attribute 'modules' 

謝謝。

+0

問題似乎是spyder,如果我在控制檯上工作,我沒有任何錯誤。 –

回答

2

我猜想,這個問題是關於通配符進口

from tensorflow.python import * 

,因爲它說的Pep 8 Guide

Wildcard imports (from module import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools (...)

您是否嘗試過通過名字導入每個使用的模塊,並刪除通配符進口?

+0

但我從來沒有用通配符顯式導入任何東西,我只是**將tensorflow導入爲tf **,「像其他人一樣」,通配符是隱式使用的。我對tensorflow很陌生,所以任何額外的信息都是有幫助的。無論如何,我會嘗試你的方法,謝謝。 –