Fix My Tutorial
Report

Simple hello world using TensorFlow

Open the original tutorial
Fixed Python 3.12 · checked 16 Oct 2026 · model cost $0.014

The original code failed with an AttributeError because TensorFlow 2.x removed the tf.Session API in favor of eager execution. After applying the fix, the hello constant is evaluated directly without creating a session, so the tutorial now runs successfully under Python 3.12 with TensorFlow 2.x.

3 changes to make it work today

Create constant op

s3 · run_code migrate

In TensorFlow 2.x eager execution, tensors evaluate immediately. Printing the tensor directly shows its value without needing a session.

@@ -8,2 +8,3 @@
hello = tf.constant('Hello, TensorFlow!')
+print(hello)

Sources

  • Fixing the "AttributeError: module 'tensorflow' has no attribute 'Session'" Error - GeeksforGeeksThe error message "AttributeError: module 'tensorflow' has no attribute 'Session'" typically occurs when using TensorFlow version 2.x. This error is due to the fact that the `Session` object, which was a core component in TensorFlow 1.x for executing operations in a computational graph, has been removed in TensorFlow 2.x. The new version of TensorFlow defaults to eager execution, which evaluates operations immediately without the need for a session, making the development process more intuitive and straightforward. [...] ## Why Does This Error Occur?
  • Module: tf.compat.v1  |  TensorFlow v2.16.1`class InteractiveSession`: A TensorFlow `Session` for use in interactive contexts, such as a shell.

Start TensorFlow session

s4 · run_code migrate

tf.Session was removed in TensorFlow 2.x. Eager execution evaluates operations immediately.

@@ -1,2 +1 @@
-# Start tf session
-sess = tf.Session()
+# No session needed in TensorFlow 2.x eager execution

Sources

  • Fixing the "AttributeError: module 'tensorflow' has no attribute 'Session'" Error - GeeksforGeeksThe error message "AttributeError: module 'tensorflow' has no attribute 'Session'" typically occurs when using TensorFlow version 2.x. This error is due to the fact that the `Session` object, which was a core component in TensorFlow 1.x for executing operations in a computational graph, has been removed in TensorFlow 2.x. The new version of TensorFlow defaults to eager execution, which evaluates operations immediately without the need for a session, making the development process more intuitive and straightforward. [...] ## Why Does This Error Occur?
  • Module: tf.compat.v1  |  TensorFlow v2.16.1`class InteractiveSession`: A TensorFlow `Session` for use in interactive contexts, such as a shell.

Run graph and print result

s5 · run_code migrate

The print in step s3 already outputs the tensor value. This step is kept for tutorial structure but does no work.

@@ -1,2 +1 @@
-# Run graph
-print(sess.run(hello))
+# The value was already printed above

Sources

  • Fixing the "AttributeError: module 'tensorflow' has no attribute 'Session'" Error - GeeksforGeeksThe error message "AttributeError: module 'tensorflow' has no attribute 'Session'" typically occurs when using TensorFlow version 2.x. This error is due to the fact that the `Session` object, which was a core component in TensorFlow 1.x for executing operations in a computational graph, has been removed in TensorFlow 2.x. The new version of TensorFlow defaults to eager execution, which evaluates operations immediately without the need for a session, making the development process more intuitive and straightforward. [...] ## Why Does This Error Occur?

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error. The issue opens on GitHub under your own account, filled in for you to review.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/CgyYcY2AMNk.svg)](https://fix-my-tutorial.onrender.com/r/CgyYcY2AMNk)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/CgyYcY2AMNk"><img src="https://fix-my-tutorial.onrender.com/badge/CgyYcY2AMNk.svg" alt="Fix My Tutorial"></a>