我一直在学习张量流,直到现在一切都很好。我甚至使用GPU来进行张量流计算。但是当我将 import tensorflow作为tf 命令运行时突然出现以下错误:
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
很容易修复,我只是重置控制台。但它非常烦人,因为我每次运行脚本后都需要重置控制台。 (即使脚本只是“import tensorflow as tf”)
当我使用F5运行整个脚本时,我得到了一个不同的错误,即使唯一的命令是 import tensorflow as tf 。 我在Ubuntu 16.04.3 LTS上运行spyder 2.7 Python 2.7.12中的脚本。
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 :(得分:2)
我猜这个问题出在通配符导入
上from tensorflow.python import *
所述
应避免使用通配符导入(来自模块导入*),因为它们不清楚命名空间中存在哪些名称,使读者和许多自动化工具混淆(...)
您是否尝试按名称导入每个已使用的模块并删除通配符导入?