import tensorflow.compat.v1 as tf ModuleNotFoundError: No module named 'tensorflow.compat'
时间: 2023-12-09 10:35:57 浏览: 198
这个错误通常是因为你的TensorFlow版本不兼容所导致的。你可以尝试以下两种解决方法:
1.卸载当前的TensorFlow版本并安装与你的代码兼容的版本。你可以使用以下命令卸载TensorFlow:
```
pip uninstall tensorflow
```
然后使用以下命令安装与你的代码兼容的版本:
```
pip install tensorflow==2.3.1 -i https://pypi.douban.com/simple
```
2.按照博客所述,将`import tensorflow as tf`改为`import tensorflow.compat.v1 as tf`。这将使你的代码与TensorFlow 1.x版本兼容。
```python
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
```
阅读全文
相关推荐









