Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tensorflow' has no attribute '_version_'
时间: 2023-12-16 21:04:29 浏览: 187
这个错误是因为你尝试访问 TensorFlow 的属性 `_version_`,但是它不存在。正确的属性名称是 `__version__`,所以你需要将 `_version_` 改为 `__version__`。下面是一个演示:
```
import tensorflow as tf
print(tf.__version__) # 正确的属性名称是 __version__
```
这应该会输出安装在你的系统上的 TensorFlow 版本号。如果你仍然遇到问题,可能是因为你的 TensorFlow 安装存在问题,你可以尝试重新安装它。
相关问题
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tensorflow' has no attribute '__version__'
这个错误通常是因为你的 TensorFlow 环境没有正确安装或配置造成的。你可以尝试重装 TensorFlow 或者检查你的代码中是否有导入 tensorflow 模块的语句,如果有,可以尝试修改为 from tensorflow import VERSION,并且在代码的其他部分中使用 VERSION 属性获取版本号信息。希望能够帮到你。
>>> print(tf.__version__) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'tensorflow' has no attribute '__version__'
这个错误可能是因为您的 TensorFlow 版本较低,不支持 `tf.__version__` 属性。在较早的 TensorFlow 版本中,可以使用以下方式来获取 TensorFlow 版本号:
```
import tensorflow as tf
print(tf.VERSION)
```
如果您使用的是 TensorFlow 1.x 版本,可以使用以下方式获取 TensorFlow 版本号:
```
import tensorflow as tf
print(tf.__version__)
```
在 TensorFlow 2.x 中,以上两种方式都可以使用。希望这个回答能够解决您的问题。
阅读全文