gpt4 book ai didi

python-2.7 - 属性错误 : 'NoneType' object has no attribute 'modules' in tensorflow

转载 作者:行者123 更新时间:2023-12-02 10:45:10 25 4
gpt4 key购买 nike

我一直在学习tensorflow,直到现在一切都很好。我什至使用 GPU 用 tensorflow 进行了一些计算。但是在运行 时突然出现以下错误将 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 运行整个脚本时,我得到了一个不同的错误,即使唯一的命令是 将 tensorflow 导入为 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'

谢谢你。

最佳答案

我猜问题出在通配符导入上

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 (...)



您是否尝试过按名称导入每个使用的模块并删除通配符导入?

关于python-2.7 - 属性错误 : 'NoneType' object has no attribute 'modules' in tensorflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46851990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com