ModuleNotFoundError No module named 'tensorflow.python.training'
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
ModuleNotFoundError: No module named 'tensorflow.python.training' usually means your code is importing a TensorFlow internal module instead of a supported public API. It can also happen when TensorFlow is missing, partially installed, or when an older package expects an internal path that no longer exists in your environment.
Prefer Public TensorFlow Imports
TensorFlow examples and guides use the public package import:
That import is stable across supported releases. By contrast, tensorflow.python.* is an internal implementation namespace. Code that imports directly from it may work in one release and break in another.
If your code currently looks like this:
replace it with a public API when possible. For checkpointing, modern TensorFlow code typically uses tf.train.Checkpoint or Keras model saving.
Verify the Environment Before Refactoring Further
If the public import itself fails, the problem is more basic: TensorFlow is not installed in the interpreter you are running. Confirm the interpreter and package path first.
If pip show returns nothing, install TensorFlow into the active environment and retry. Running python -m pip is safer than calling pip directly because it ties installation to the same interpreter you are about to use.
Handle Legacy TensorFlow 1 Code Carefully
Some older tutorials and third-party packages reached into TensorFlow internals because TensorFlow 1 code often relied on implementation details. If you are migrating that code, move toward public APIs under tf, tf.keras, or tf.compat.v1 instead of trying to preserve every old internal import.
For example, a legacy training utility may be better rewritten around Keras callbacks:
If the failing import comes from a dependency rather than your own code, update that dependency first. A package pinned to an outdated TensorFlow internals layout may never be reliable on a modern installation.
It also helps to isolate the problem in a clean virtual environment. If the same script works there, your original environment likely contains conflicting packages, old editable installs, or an interpreter mismatch rather than a real TensorFlow API issue.
Common Pitfalls
The biggest mistake is trying to "fix" the error by hunting for another internal tensorflow.python.* path. That treats the symptom, not the cause. Internal imports are not a stable compatibility contract.
Another problem is mixing environments. You may install TensorFlow in one virtual environment and run the script from another interpreter in your IDE, notebook kernel, or shell. Always verify sys.executable when debugging import issues.
Partial installs can also cause confusing behavior. If TensorFlow installation was interrupted, uninstall and reinstall cleanly rather than assuming the package tree is intact.
Finally, if a notebook still shows the same error after installation, restart the kernel. Long-lived Python sessions often keep stale import state.
Summary
- '
tensorflow.python.trainingis an internal path and should not be treated as a public API.' - Prefer
import tensorflow as tfand public APIs such astf.train.Checkpointor Keras callbacks. - Verify that TensorFlow is installed in the exact interpreter that runs your code.
- Update old dependencies that import TensorFlow internals instead of patching around them.
- Restart notebook kernels or shells after installation changes when the error persists.

