ModuleNotFoundError: No module named 'tensorflow'
Resolves ModuleNotFoundError for tensorflow via interpreter-matched install. Use when `import tensorflow` fails with No module named 'tensorflow'. Not for DLL/.so load failures or CUDA setup problems.
TL;DR: Install tensorflow in the Python you are actually running: pip install tensorflow. If pip says it is already installed, you have an interpreter mismatch, check python -c "import sys; print(sys.executable)" against where pip installed it. On Apple Silicon use tensorflow-macos, not tensorflow.
The error:
ModuleNotFoundError: No module named 'tensorflow'Fix
Run
python -c "import sys; print(sys.executable)"thenpython -m pip show tensorflowExpected: either shows tensorflow info or confirms it is missing from this interpreterInstall:
python -m pip install tensorflow(ortensorflow-macoson Apple Silicon) Expected: Successfully installed tensorflowVerify:
python -c "import tensorflow as tf; print(tf.__version__)"Expected: prints the version, no error
When this applies
- No module named 'tensorflow' on import
- pip list shows tensorflow but the script still fails (interpreter mismatch)
When this does not apply
- import fails with a DLL or .so error (installed but broken)
- you need GPU support, that is a separate install decision
Version compatibility
tensorflow 2.x CPU. For GPU on Linux use the CUDA-enabled build per the TF install docs; Apple Silicon uses tensorflow-macos + tensorflow-metal.
Why it happens
TensorFlow is a large package that people often install with one pip/python and run with another (system python, venv, conda, notebook kernel). The module simply is not on sys.path of the running interpreter.
Edge cases
- Always use
python -m pipso the installer targets the interpreter you run. - In notebooks, restart the kernel after installing.
- tensorflow does not publish an official Windows GPU wheel for 2.11+; CPU wheel or WSL2 instead.