This error means the Python process running your code cannot resolve the requested tensorflow.keras module. First verify that TensorFlow is installed in that exact Python environment; only then investigate whether a TensorFlow/Keras version change requires a different import or legacy setup. The error text alone does not reveal which cause applies.
1. Check the Python environment that runs your code
A common source of import errors is installing a package into one Python environment and running the program with another. Use the same python command, virtual environment, IDE interpreter, or notebook kernel that launches the failing code:
As an Amazon Associate I earn from qualifying purchases.
python -c "import sys; print(sys.executable)"
python -m pip show tensorflow keras tf-keras
The first command prints the active interpreter path. The second checks whether TensorFlow, Keras, or the legacy package is installed for that interpreter. TensorFlow recommends pip-based installation and provides a verification example in its official pip installation guide.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →If TensorFlow is missing, use that guide’s steps for your operating system, processor architecture, and Python version. Its supported-platform and Python-version matrix can change, so check the current guide rather than relying on an old version command copied from elsewhere.
#1 Best Overall
2. Check for a local name conflict
Look in your project for a file named tensorflow.py or a directory named tensorflow. A local name can interfere with Python resolving the installed package. If you rename one, remove any matching __pycache__ directory and retry the import.
3. Check TensorFlow and Keras versions
If TensorFlow is installed but the import still fails, note the installed versions from pip show and check the import in the same environment. A TensorFlow/Keras upgrade may affect which Keras namespace a project should use.
Rank #2
Starting with TensorFlow 2.16, installing TensorFlow installs Keras 3 by default, and tf.keras resolves to Keras 3. This does not, by itself, prove that an import error is caused by the Keras 2-to-3 change; verify the environment and the exact versions first. Keras documents this behavior in its Getting started with Keras guide.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →4. Choose a Keras 3 migration or legacy Keras 2
Once you confirm the version situation, choose the path that fits the project’s dependencies. Do not mechanically replace every import: check the APIs, integrations, and other packages the application uses.
| Path | What to do | When it fits |
|---|---|---|
| Use Keras 3 | Follow the Keras 3 migration guide; for example, use import keras and from keras import layers. |
Choose this when the project and its dependencies can use Keras 3. Compatibility with Keras 2 is broad, but not total. |
| Keep legacy Keras 2 | Install tf_keras and, before importing TensorFlow, set TF_USE_LEGACY_KERAS=1. Keras documents this option in its Getting started with Keras guide. |
Choose this when the project needs legacy Keras 2 behavior or dependencies are not ready to migrate. |
The legacy environment setting affects packages that import tf.keras in that Python process. If you need to limit the change’s scope, Keras notes that importing tf_keras directly is another option. Avoid casually mixing separate Keras package namespaces in one application.
5. Restart and verify the import
- After installing a package or changing an environment variable, restart the Python process or notebook kernel.
- Run a minimal import using the same interpreter that runs the application. For example, to test the Keras 3 namespace, run
python -c "import keras; print(keras.__version__)". For TensorFlow’s installation check, use the verification example in its pip installation guide. - If the minimal test works but the application still fails, confirm that the application uses the same interpreter and inspect its imports and dependencies.
If it still fails, capture these details
- The full traceback, not only the exception line.
- The interpreter path printed by
sys.executable. - The TensorFlow, Keras, and
tf-keraspackage versions, if installed. - Your operating system, processor architecture, Python version, and whether you use a notebook, IDE, or virtual environment.
- Whether the failure began after an installation, upgrade, or code change.
Without those details, it is not possible to identify the specific root cause or guarantee one installation command will fix it. TensorFlow’s installation guide also links to troubleshooting information for installation and import problems.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




