'tensorflow' has no attribute 'config'
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
AttributeError: module 'tensorflow' has no attribute 'config' usually points to one of two problems: you are running TensorFlow 1.x code against a TensorFlow 2.x API example, or Python is importing the wrong module because a local file or package named tensorflow is shadowing the real library.
First Check the Imported Module
Before changing code, verify what Python actually imported:
If tf.__file__ points to your project directory rather than the installed package location, you probably have a local file such as tensorflow.py or a folder named tensorflow shadowing the real library.
That is one of the most common causes of mysterious missing attributes.
tf.config Is a TensorFlow 2 API
The tf.config namespace is part of TensorFlow 2.x and is commonly used for GPU discovery, memory growth, and device configuration.
For example:
If you are actually running TensorFlow 1.x, that attribute will not exist. In that case, the fix is either:
- upgrade to TensorFlow 2 if your code expects TensorFlow 2 APIs
- rewrite the code to use TensorFlow 1 compatible APIs
Version Mismatch in Practice
Check the installed version with:
If the version is 1.x and the code uses tf.config, you have a version mismatch. Modern examples assume TensorFlow 2, while older environments may still be pinned to TensorFlow 1 for legacy reasons.
In TensorFlow 1.x, device and session configuration often lived in different APIs such as ConfigProto:
That is not a direct replacement for every tf.config call, but it shows why old and new examples can diverge so sharply.
Environment Problems Are Also Common
Another frequent cause is using the wrong virtual environment. You may have installed TensorFlow 2 in one environment and be running the script with a different interpreter.
That is why checking all three of these together is important:
- '
python --version' - '
which pythonorwhere python' - '
pip show tensorflow'
If they do not line up, you may be installing TensorFlow into one interpreter and running another.
This is especially common in notebook environments, IDEs, and machines that have both system Python and one or more virtual environments installed.
A Good Debugging Flow
Use this order:
- print
tf.__file__to rule out module shadowing - print
tf.__version__to confirm the installed TensorFlow major version - confirm the active interpreter and environment
- decide whether the code should target TensorFlow 1 compatibility or TensorFlow 2 APIs
That sequence usually resolves the error quickly.
Common Pitfalls
- Renaming nothing and repeatedly reinstalling TensorFlow when the real problem is a local
tensorflow.pyfile. - Assuming all TensorFlow tutorials use the same major version of the API.
- Mixing TensorFlow 1 compatibility code with TensorFlow 2 device-configuration examples.
- Installing TensorFlow into one environment and running the script from another.
- Fixing the import error without checking whether the rest of the codebase expects TensorFlow 1 or TensorFlow 2 behavior.
Summary
- '
tf.configis a TensorFlow 2 API, so the error often means you are not actually running TensorFlow 2.' - A shadowing local module named
tensorflowcan produce the same symptom. - Print
tf.__version__andtf.__file__before making bigger changes. - Use TensorFlow 1 compatibility APIs only if the project genuinely targets that older runtime.
- Most fixes come down to version alignment or import-path cleanup, not to exotic TensorFlow bugs.
Related reading
- ''tensorflow'' has no attribute ''config''
- ''tensorflow'' has no attribute ''to_int32''
- Tensorflow hashtable lookup with arrays
- Tensorflow hierarchical object detection
- Tensorflow Hierarchical Softmax Implementation
- TensorFlow Horovod NCCL and MPI
- Tensorflow How does tf.get_variable work?
- TensorFlow how is dataset.train.next_batch defined?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.