Fix ModuleNotFoundError No Module Named TensorFlow

When a Python script stops at import tensorflow, the active environment cannot find the package. TensorFlow is the Python package that provides the tensorflow import.

This article explains how to install TensorFlow in the Python environment running your code and what to check if the import still fails.

TL;DR

Install TensorFlow with the Python interpreter that runs your script, then test the import in that environment.

  • Use python -m pip install tensorflow so pip belongs to that Python.
  • In Jupyter or an IDE, check its selected kernel or project interpreter.
  • Check TensorFlow’s current Python and platform support if installation fails.

What Does No Module Named TensorFlow Mean?

Python raises ModuleNotFoundError when a requested import is absent from its search path. The distribution name is tensorflow, written in lowercase in the import statement.

Python searches the active environment when resolving an import.

How to Fix the TensorFlow Import Error Step by Step

The sequence below checks package metadata, installs TensorFlow and verifies the import.

Step 1: Check the Python running your code

From the project terminal, run these checks to identify the executable and see whether its package metadata lists TensorFlow.

python --version
python -m pip --version
python -m pip show tensorflow

If the final command says the package is missing, install through this Python. If it shows a package location, compare it with the interpreter selected by your IDE or notebook.

Step 2: Install TensorFlow in that environment

The current TensorFlow guide lists installation paths for supported platforms.

For this repair, install through the selected interpreter with the commands below. GPU configuration is a separate check after Python can import the package.

python -m pip install --upgrade pip
python -m pip install tensorflow

Step 3: Verify the import

After installation, test the top-level import in the same project terminal.

python -m pip show tensorflow

This read-only package check confirms which location pip reports. A successful check is not a substitute for testing the import in the application itself.

What If TensorFlow Still Cannot Be Imported?

If the package check succeeds but import still fails, inspect the module path and project filenames before reinstalling.

CaseCheckNext step
PyCharm projectProject interpreter in settingsSelect the environment containing TensorFlow or install from that interpreter.
Jupyter notebookActive kernel, not only the server shellInstall in the kernel’s Python, then restart the kernel.
No matching distributionPython version and operating systemCompare the current install matrix and PyPI wheels with your setup.
Only a submodule failsExact import pathtensorflow.keras is part of TensorFlow. TensorFlow 2 removed some older example paths, so tensorflow.examples.tutorials may require a current tutorial instead.
Import resolves to a project fileFiles or folders named tensorflowRename the conflict and remove its stale __pycache__.

PyPI lists TensorFlow 2.21.0 for Python 3.10 and later, with wheels through CPython 3.13. Verify the exact files available for your operating system before selecting a Python build.

TensorBoard has its own package if that is the missing import. For general installation steps, see AskPython’s Python pip guide and SciPy installation guide.

Alternative TensorFlow Installation Methods

Choose the installation route based on how the project runs Python.

SetupWhere to install
JupyterInto the Python environment selected by the active kernel, then restart it.
Virtual environmentActivate the project environment and use its Python executable with pip.
Platform-specific setupFollow the install route documented for that platform.

What to Learn Next

PyImageSearch University offers structured computer-vision instruction. Check its current syllabus and access terms against your goals before choosing it.

  • Run one small TensorFlow tutorial in the environment you repaired.
  • Keep its Python executable and install method with the project notes.
  • Choose a course only after checking its current syllabus and terms.

Conclusion: Install TensorFlow in the Active Environment

Install TensorFlow through the Python that runs the project, then verify the import there. For platform-specific commands, use the official TensorFlow pip guide.

FAQ

These answers cover common environment and package-name questions.

Why does pip show TensorFlow but Python cannot import it?

The pip command may belong to a different interpreter. Run python -m pip show tensorflow and launch your code with that same Python executable.

How do I install TensorFlow for a Jupyter notebook?

Use the Python environment selected by the notebook kernel, install TensorFlow there, then restart the kernel and test import tensorflow.

Does tensorflow.keras need a separate installation?

tensorflow.keras is part of TensorFlow. If that import fails, first confirm the top-level TensorFlow import works and check that your code uses a supported path.

Kumar Akshat
Kumar Akshat
Articles: 27