Python
TensorFlow
TensorFlow Probability
ModuleNotFoundError
Python Error

No module named 'tensorflow_probability'

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

ModuleNotFoundError: No module named 'tensorflow_probability' means the Python interpreter you are running cannot import the TensorFlow Probability package. In most cases, the cause is simple: the package is not installed in the active environment, or it is installed in a different environment from the one running your script or notebook.

Install the package in the right environment

TensorFlow Probability is a separate package from TensorFlow. Installing TensorFlow alone does not automatically provide tensorflow_probability.

bash
python -m pip install tensorflow-probability

Using python -m pip is important because it ties the installation to the same interpreter you are invoking. Plain pip install ... can accidentally target a different environment.

After installation, a quick check is:

bash
python -c "import tensorflow_probability as tfp; print(tfp.__version__)"

If that succeeds, the package is available to that interpreter.

Environment mismatches are very common

Many developers install the package into one virtual environment and run the code from another. Jupyter notebooks add another layer of confusion because the notebook kernel can point at a different interpreter from the terminal where the package was installed.

That is why "but I already installed it" is often true and still not enough. The real question is whether you installed it into the exact environment running the code.

To check that, inspect the interpreter path:

python
import sys
print(sys.executable)

Run that in the failing environment, then compare it to the interpreter you used for installation.

Version compatibility still matters

Sometimes the package is installed, but the environment is broken because TensorFlow and TensorFlow Probability versions are incompatible. In those cases, the import error may look different, but version mismatches are still worth checking when installation alone does not solve the problem.

The practical fix is to install matching versions intentionally instead of mixing packages casually:

bash
python -m pip install tensorflow==2.16.1 tensorflow-probability==0.24.0

The exact versions depend on the environment you are targeting, but the broader lesson is to manage them together rather than treat them as unrelated packages.

Clean environments are easier to debug

If the environment is already messy, creating a fresh virtual environment is often faster than repairing it in place.

bash
1python -m venv .venv
2source .venv/bin/activate
3python -m pip install --upgrade pip
4python -m pip install tensorflow tensorflow-probability

That removes a lot of ambiguity from the diagnosis.

The same principle applies to notebooks. If a notebook still cannot import the package after installation, the kernel itself may need to be restarted or reattached to the correct interpreter.

That small step is easy to miss. A package can be installed correctly, yet the notebook process may still be holding onto the old environment state until the kernel is restarted.

Common Pitfalls

  • Installing TensorFlow and assuming TensorFlow Probability comes with it automatically.
  • Using pip from one environment and python from another.
  • Forgetting that Jupyter kernels may use a different interpreter than the terminal.
  • Ignoring version compatibility between TensorFlow and TensorFlow Probability.
  • Trying many install commands without first checking which interpreter is actually running the code.

Summary

  • 'tensorflow_probability is a separate package and must be installed explicitly.'
  • Use python -m pip install tensorflow-probability so installation targets the correct interpreter.
  • If the import still fails, verify which environment or notebook kernel is running the code.
  • Check TensorFlow and TensorFlow Probability version compatibility when the environment is inconsistent.
  • A fresh virtual environment is often the fastest clean fix.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.