module 'tensorflow' has no attribute 'absolute_import'

image
这个error猝不及防,在查看了tensorflow API的版本后,做了如下更改

# from tensorflow import *
from tensorflow.python import *

module ‘XXX’ has no attribute ‘XXX’
解决方案:(1)module未导入成功;(2)版本容错问题。

error分析原因
本人环境是tensorflow 1.10
因为有朋友在tensorflow1.3版本上并无此错误,故直接查看了1.3版本与出错的init.py之间的区别,即做出了上述尝试,成功。

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# pylint: disable=wildcard-import
from tensorflow.python import *  # 出错参考点
# pylint: enable=wildcard-import

from tensorflow.python.util.lazy_loader import LazyLoader
contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib')
del LazyLoader

del absolute_import
del division
del print_function

# These symbols appear because we import the python package which
# in turn imports from tensorflow.core and tensorflow.python. They
# must come from this module. So python adds these symbols for the
# resolution to succeed.
# pylint: disable=undefined-variable
del python
del core

对比出错init

from __future__ import absolute_import
from tensorflow import *  # 与上面版本的init有出入

from .sg_util import sg_opt
from .sg_main import *
from .sg_logging import *
from .sg_train import *
from .sg_queue import sg_producer_func
from .sg_layer import sg_emb

from . import sg_optimize
from . import sg_data
from . import sg_initializer

from ._version import __version__


__author__ = '[email protected]'


#
# augmenting tensorflow Variable and Tensor type by injecting custom methods
#

modules = ['sg_activation', 'sg_metric', 'sg_layer', 'sg_loss', 'sg_transform', 'sg_net']
for mod in modules:
    sg_inject(__path__[0], mod)

猜你喜欢

转载自blog.csdn.net/u010801994/article/details/81978712