In this article, we will discuss on how to solve the no module named tensorflow keras for all the programmers who encountered this error.
Why the no module named ‘tensorflow.keras’ occurs?
The error no module named tensorflow keras usually occurs because the python interpreter cannot find the installed library tensorflow that consists of keras package.
Alternatively, the error occurs because you may have numerous versions of python installed on your system and the keras module is not installed.
Also read : [SOLVED] Modulenotfounderror: no module named cryptography
How to solve the no module named tensorflow keras?
Time needed: 3 minutes
Here are the solutions to solve the modulenotfounderror: no module named ‘tensorflow.keras’
- Solution 1: Install tensorflow keras
The most possible reason is that the python hasn’t provided a standard keras library.
Also, you cannot install it with the following command: pip install keras .
Rather, you should have installed the TensorFlow module through the use of the pip package.
To solve this error, in your project root directory open a command prompt and type the following command to install the tensorflow:
pip install tensorflow
This is the basic command to install a tensorflow in the path virtual environment on Windows, Linux, and MacOS
Just insure that the pip version on your system is updated. If it is not, you will use the following two commands in your command prompt(CMD):
“ python -m pip install –upgrade pip “
or
“ pip install tensorflow ”
- Solution 2: Install the Correct Path
If the error will continue, even though you already installed the tensorflow library.
Although, the pip is installed yet it is not installed in the correct path.
For this reason, it is not able to install the library with the use pip package in the correct path.
To solve the problem with the virtual path environment in Windows. Just follow the steps for the next solution.
- Solution 3: Show the Python Location
Just open the location of the folder where you installed the Python, then open the command prompt and just type this command:
“ where python “
After you type the command above the result will be like this.

- Solution 4: Open Scripts Folder
When you opened the Python folder, just browse and open the folder of scripts and you need to copy the location.
Moreover, you need to check the folder if it consists of the pip file.

- Solution 5: Open Scripts Directory
Then in your scripts directory open your command prompt(CMD) with the use of the “cd” command and then copy the location of the folder script.

- Solution 6: Installation Module for tensorflow
This is the command to install the library using pip install tensorflow command.

- Solution 7: Install tensorflow in Python3
The following command below is a command to install the tensorflow in python 3:
“ python3 -m pip install tensorflow “or
“ pip3 install tensorflow “
- Solution 8: Install tensorflow in server side
If you encounter the error on server side. Type this command:
“pip install –user tensorflow“
- Solution 9: Install tensorflow in Ubuntu
This is the command to install tensorflow in Ubuntu:
“ sudo apt install tensorflow “
Diagnostic checklist for “No module named ‘tensorflow'”
- Verify pip install target. Run
pip show tensorflow— if not installed, runpip install tensorflow. - Check the active Python interpreter.
which python(mac/Linux) orwhere python(Windows). Both pip and python must point to the same environment. - Check virtual environment activation. If you use venv/conda, activate before installing:
source .venv/bin/activate. - Rule out uppercase/lowercase. Python imports are case-sensitive:
import PyPDF2notimport pypdf2. - Rule out the pip-vs-package-name mismatch. Some packages install under a different name than you import (e.g.
pip install beautifulsoup4→import bs4).
Installing tensorflow — deep learning framework
# Standard pip install pip install tensorflow # With CUDA support (Linux/Windows with GPU) # PyTorch: use the selector at https://pytorch.org/get-started/locally/ # TensorFlow: pip install tensorflow[and-cuda] # CPU-only install pip install tensorflow --index-url https://download.pytorch.org/whl/cpu
Common causes for missing deep-learning modules
- CUDA / cuDNN version mismatch. GPU wheels are pinned to a CUDA version. Check the framework’s install page for your CUDA.
- Python version too new. PyTorch/TensorFlow support the latest Python by a few weeks. Pin to 3.11 or 3.12 if 3.13 fails.
- M1/M2 Mac Metal build. Apple silicon needs Metal-specific wheels (torch has these).
- Notebook kernel mismatch. Jupyter may pick a different Python. Install with
%pip install tensorflow.
Working code example
import tensorflow
print(tensorflow.__version__)
# For PyTorch: verify CUDA
# import torch
# print(torch.cuda.is_available())
# For TensorFlow: verify GPUs
# import tensorflow as tf
# print(tf.config.list_physical_devices('GPU'))
Best practices
- Use conda for deep learning. It manages CUDA + cuDNN alongside Python packages — much smoother than pip alone.
- Pin the framework + CUDA version. Deep learning models are very version-sensitive.
- Consider Docker. NVIDIA publishes CUDA-ready base images that make setup trivial.
Official documentation
Frequently Asked Questions
What is Python ModuleNotFoundError and what causes it?
ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.
How do I fix ‘ModuleNotFoundError: No module named X’?
Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.
Why does my code work in one environment but not another?
Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.
Is ModuleNotFoundError the same as ImportError?
ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.
Where can I find more ModuleNotFoundError fixes?
Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.
Conclusion
To conclude in this article, we already provided the solutions to the error modulenotfounderror no module named tensorflow keras that is always encountered by all python programmers.




