zgkjzf 发表于 2020-4-2 09:44

module 'tensorflow' has no attribute 'compat'求助

安装tensorflow2.1 一import tensorflow就报下面错误 怎么解决
2020-04-02 09:40:07.185822: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
Traceback (most recent call last):
File "C:/Users/zaf/Desktop/jd/test2.py", line 1, in <module>
    import tensorflow
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 46, in <module>
    from . _api.v2 import compat
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 39, in <module>
    from . import v1
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 32, in <module>
    from . import compat
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\compat\__init__.py", line 39, in <module>
    from . import v1
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\compat\v1\__init__.py", line 29, in <module>
    from tensorflow._api.v2.compat.v1 import app
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 39, in <module>
    from . import v1
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 32, in <module>
    from . import compat
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\compat\__init__.py", line 39, in <module>
    from . import v1
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\compat\v1\__init__.py", line 667, in <module>
    from tensorflow_estimator.python.estimator.api._v1 import estimator
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1 import estimator
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1.estimator import experimental
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
    from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 33, in <module>
    from tensorflow_estimator.python.estimator import estimator
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 53, in <module>
    from tensorflow_estimator.python.estimator import util as estimator_util
File "C:\Program Files\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\util.py", line 75, in <module>
    class _DatasetInitializerHook(tf.compat.v1.train.SessionRunHook):
AttributeError: module 'tensorflow' has no attribute 'compat'

luo青山 发表于 2020-4-2 10:27

你是用的TF2吧,这个一般是不兼容TF1.x的代码

luo青山 发表于 2020-4-2 10:29

tf2.x中丢弃了这个方法,所有报错,可以换TF版本回1.x,或者修改代码,怎么修改百度谷歌一下

Zhengyu123 发表于 2020-4-2 10:33

把import tensorflow as tf 改成 import tensorflow.compat.v1 as tf
如果还不行,建议卸载重装

zgkjzf 发表于 2020-4-2 12:09

Zhengyu123 发表于 2020-4-2 10:33
把import tensorflow as tf 改成 import tensorflow.compat.v1 as tf
如果还不行,建议卸载重装

重装之后问题依旧

zgkjzf 发表于 2020-4-2 12:11

luo青山 发表于 2020-4-2 10:29
tf2.x中丢弃了这个方法,所有报错,可以换TF版本回1.x,或者修改代码,怎么修改百度谷歌一下

现在问题是import tensorflow就报这个错,跟没按上似的,不是版本问题0

zgkjzf 发表于 2020-4-2 12:20

安装gpu版本的tensorflow后不报错
页: [1]
查看完整版本: module 'tensorflow' has no attribute 'compat'求助