Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Fix “ModuleNotFoundError: No module named ‘tensorflow.keras’”

This Python import error may mean TensorFlow is missing from the active environment, a local file is shadowing the package, or the project needs a Keras 3 or legacy Keras 2 adjustment.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

  1. After installing a package or changing an environment variable, restart the Python process or notebook kernel.
  2. 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.
  3. If the minimal test works but the application still fails, confirm that the application uses the same interpreter and inspect its imports and dependencies.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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-keras package 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.