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,覆盖了源码,修改文件名后正常