简体   繁体   English

模块 'tensorflow' 没有属性 'random'

[英]module 'tensorflow' has no attribute 'random'

蟒蛇代码 i'm trying to generate seed using TensorFlow 2.1 but this error appears module 'TensorFlow' has no attribute 'random'我正在尝试使用 TensorFlow 2.1 生成种子,但出现此错误模块“TensorFlow”没有属性“随机”

I suspect that you think you're using TensorFlow 2.0 but actually, it is a previous version of tensorflow.我怀疑您认为您使用的是 TensorFlow 2.0,但实际上,它是 tensorflow 的先前版本。

It's easy to check:很容易检查:

import tensorflow as tf
print(tf.__version__)

This should produce output like this:这应该产生这样的输出:

2.1.0

If not, you know you have the wrong TensorFlow version installed.如果没有,您就知道您安装了错误的 TensorFlow 版本。


It's also possible that you have multiple versions of python installed.您也可能安装了多个版本的 python。 For example:例如:

  • Python 3.6 might be installed with TensorFlow 1.x, and Python 3.6 可能与 TensorFlow 1.x 一起安装,并且
  • Python 3.7 might be installed with TensorFlow 2.x. Python 3.7 可能与 TensorFlow 2.x 一起安装。

In this case, just be careful that the version of Python being used by Jupyter Notebook is the version of Python with TensorFlow 2.x installed.在这种情况下,请注意 Jupyter Notebook 使用的 Python 版本是安装了 TensorFlow 2.x 的 Python 版本。

just want to make sure只是想确定

run this command then restart the runtime pip install --upgrade tensorflow and then try that code again运行此命令然后重新启动运行时pip install --upgrade tensorflow然后再次尝试该代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM