AttributeError: module ‘tensorflow‘ has no attribute ‘compat‘

AttributeError: module ‘tensorflow’ has no attribute 'compat’问题解决

Traceback (most recent call last):
  File "E:/Pythonbase/.../.../Test.py", line 4, in <module>
    import tensorflow as tf
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\__init__.py", line 64, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\framework\framework_lib.py", line 25, in <module>
    from tensorflow.python.framework.ops import Graph
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\framework\ops.py", line 64, in <module>
    from tensorflow.python.platform import app
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\platform\app.py", line 23, in <module>
    from absl.app import run as _run
  File "E:\Anaconda\envs\TF2.1\lib\site-packages\absl\app.py", line 35, in <module>
    import pdb
  File "E:\Anaconda\envs\TF2.1\lib\pdb.py", line 76, in <module>
    import code
  File "E:\Pythonbase\...\...\code.py", line 9, in <module>
    tf.compat.v1.disable_eager_execution()
AttributeError: module 'tensorflow' has no attribute 'compat'

一开始以为tensorflow少了文件,卸载重装了好几次,都没有效果。
后来仔细看了看报错信息,发现源码会导入一个code文件

 File "E:\Anaconda\envs\TF2.1\lib\pdb.py", line 76, in <module>
    import code

而我自己也建了一个code.py,覆盖了源码,修改文件名后正常

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值