tensorflow
AttributeError
CheckpointableBase
module error
Python debugging

AttributeError module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The error AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase' occurs because CheckpointableBase was renamed to Trackable in TensorFlow 2.x. Code written for TF 1.x (or libraries depending on TF 1.x internals) references the old internal API path. The fix is to upgrade TensorFlow and the library that triggered the error, or pin compatible versions if you must stay on TF 1.x.

The Error

python
1import tensorflow as tf
2# Some library or code does:
3from tensorflow.python.training.checkpointable import CheckpointableBase
4# AttributeError: module 'tensorflow.python.training.checkpointable'
5# has no attribute 'CheckpointableBase'

This typically appears when:

  • You upgraded TensorFlow but a dependent library still uses old internal APIs
  • You are running code written for TF 1.x on TF 2.x
  • A third-party library (keras-contrib, tensorflow-addons old versions, etc.) references removed internals

What Changed

TensorFlow reorganized its internal checkpoint/tracking API across versions:

TF VersionAPI PathClass Name
TF 1.x (early)tf.python.training.checkpointableCheckpointableBase
TF 1.15tf.python.training.trackingTrackableBase
TF 2.xtf.python.training.trackingAutoTrackable
python
1# TF 1.x (old)
2from tensorflow.python.training.checkpointable import CheckpointableBase
3
4# TF 2.x (current)
5from tensorflow.python.training.tracking.base import Trackable
6# Or more commonly:
7from tensorflow.python.trackable.base import Trackable  # TF 2.11+
bash
1# Upgrade TensorFlow to latest
2pip install --upgrade tensorflow
3
4# Upgrade the library that caused the error
5pip install --upgrade keras-contrib  # or whatever library triggered it
6pip install --upgrade tensorflow-addons
7pip install --upgrade tf-slim
8
9# Check for version compatibility
10pip check

Most libraries have updated to use TF 2.x APIs. Upgrading resolves the issue.

Fix 2: Pin Compatible Versions

If you must use older code:

bash
1# For code targeting TF 1.x
2pip install tensorflow==1.15.5
3
4# For code that needs checkpointable but with TF 2.x
5pip install tensorflow==2.3.4  # Some transitional versions have compatibility shims

Fix 3: Monkey-Patch (Temporary Workaround)

python
1import tensorflow as tf
2
3# Create compatibility shim
4try:
5    from tensorflow.python.training.checkpointable import CheckpointableBase
6except (ImportError, AttributeError):
7    from tensorflow.python.training.tracking.base import Trackable as CheckpointableBase
8
9# Or patch the module
10import tensorflow.python.training as training
11if not hasattr(training, 'checkpointable'):
12    from tensorflow.python.training import tracking
13    training.checkpointable = tracking

This is a temporary fix — update the actual code or library as soon as possible.

Fix 4: Update the Import in Your Code

If the error is in your own code:

python
1# BEFORE (TF 1.x)
2from tensorflow.python.training.checkpointable import CheckpointableBase
3
4class MyLayer(CheckpointableBase):
5    pass
6
7# AFTER (TF 2.x)
8import tensorflow as tf
9
10class MyLayer(tf.keras.layers.Layer):
11    pass
12# Or if you need low-level tracking:
13from tensorflow.python.trackable.base import Trackable
14
15class MyTrackable(Trackable):
16    pass

In most cases, you should use tf.keras.layers.Layer or tf.Module instead of internal tracking classes.

Fix 5: Use tf.compat.v1 for Migration

python
1import tensorflow.compat.v1 as tf
2tf.disable_v2_behavior()
3
4# Some compat.v1 paths may still work
5# But checkpointable was removed even from compat

tf.compat.v1 does not restore all internal API paths. It primarily restores the public API (sessions, placeholders, etc.).

Identifying the Source

python
1import traceback
2
3try:
4    import problematic_library
5except AttributeError as e:
6    traceback.print_exc()
7    # The traceback shows which library/file makes the bad import
bash
# Search your installed packages for the old import
grep -r "checkpointable" $(python -c "import site; print(site.getsitepackages()[0])")

This helps identify which package needs upgrading.

Common Packages That Cause This

PackageFix
keras-contribUpgrade or switch to tensorflow-addons
tf-slimpip install tf-slim>=1.1.0
tensorflow-addonspip install tensorflow-addons>=0.15.0
tensorflow-hubpip install tensorflow-hub>=0.12.0
Custom codeUpdate imports to use tf.Module or tf.keras.layers.Layer

Version Checking

python
1import tensorflow as tf
2print(tf.__version__)
3
4# Check if the old path exists
5print(hasattr(tf.python.training, 'checkpointable'))  # False in TF 2.x
6
7# Check the new path
8from tensorflow.python.training.tracking import base
9print(hasattr(base, 'Trackable'))  # True in TF 2.x

Common Pitfalls

  • Mixing TF 1.x and 2.x packages: Installing tensorflow==2.x with a library built for tensorflow==1.x causes this error. Check compatibility matrices for all ML packages.
  • Using internal APIs: tensorflow.python.* paths are internal and not guaranteed to be stable. Use public APIs (tf.keras, tf.Module, tf.saved_model) which have stability guarantees.
  • Virtual environment confusion: You may have TF 2.x installed globally but TF 1.x in a virtualenv (or vice versa). Check pip list | grep tensorflow in the active environment.
  • Cached .pyc files: Old compiled Python files may reference the removed module. Delete __pycache__ directories and .pyc files after upgrading.
  • Docker/container images: Pre-built Docker images (e.g., tensorflow/tensorflow:1.x) have old TF versions. Update your Dockerfile to use tensorflow/tensorflow:latest or a specific 2.x tag.

Summary

  • CheckpointableBase was renamed to Trackable in TensorFlow 2.x
  • The error occurs when old code or libraries reference tensorflow.python.training.checkpointable
  • Fix by upgrading TensorFlow and all dependent ML libraries to compatible versions
  • Use tf.keras.layers.Layer or tf.Module instead of internal tracking classes
  • Avoid importing from tensorflow.python.* paths — they are internal and change between versions
  • Use grep to find which installed package makes the outdated import

Course illustration
Course illustration

All Rights Reserved.