AttributeError: Module ‘TensorFlow’ has no attribute ‘set_random_seed’ error occurs when you try to “call the set_random_seed()” function on the TensorFlow version 2.x in which it does not exist.”
How to fix it?
To fix the AttributeError: Module ‘TensorFlow’ has no attribute ‘set_random_seed’ error, use the “tf.random.set_seed()” method if you are using TensorFlow version 2.x.
You can check your currently installed TensorFlow version using the below code:
import tensorflow as tf
print(tf.__version__)
Output
2.13.0
Common causes of the error
- You are using an outdated version of TensorFlow. The set_random_seed() function was removed in TensorFlow 2.0.
- You are using a different module than TensorFlow. For example, you might be using the tensorflow.compat.v1 module, which still has the set_random_seed() function.
- You have made a typo in your code.
Alternate solutions
- Upgrade your installed tensorflow version to the latest version and use the “tf.random.set_seed()” function.
- You can try checking your code for typos.
I hope you will fix your error by following this article.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.