Tensorflow
NotFoundError
libtensorflow_framework.so
Python
Machine Learning

Tensorflow NotFoundError libtensorflow_framework.so cannot open shared file or directory

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

NotFoundError: libtensorflow_framework.so: cannot open shared file or directory means the Python package is present, but the operating system cannot load one of TensorFlow's native shared libraries. That usually points to an installation mismatch, a broken environment, or a missing runtime dependency rather than a bug in model code.

The reliable fix is to stop guessing and verify the interpreter, the installed wheel, and the dynamic linker path in that order.

What The Error Actually Means

TensorFlow is not pure Python. When you run import tensorflow, Python loads extension modules that depend on shared objects such as libtensorflow_framework.so. If the file is missing, incompatible, or hidden from the linker, import fails before any of your own code runs.

This happens most often in four cases: the wrong TensorFlow wheel is installed for the platform, multiple TensorFlow packages are mixed in one environment, GPU-related native dependencies are missing, or the process starts with a library path that points at stale files.

Verify The Active Environment

First, make sure the Python executable and installed package really belong to the same environment:

bash
python -c "import sys; print(sys.executable)"
python -m pip show tensorflow
python -m pip show tensorflow-cpu

If both TensorFlow variants are installed, or if pip show reports a path outside the environment you expected, clean that up first.

Next, check whether the native library exists where the wheel installed it:

bash
1python - <<'PY'
2import site
3for path in site.getsitepackages():
4    print(path)
5PY
6
7find /path/to/site-packages/tensorflow -name 'libtensorflow_framework.so*'

If the file is not there, the wheel installation is incomplete or corrupted.

Reinstall Cleanly

The fastest fix is usually a fresh virtual environment with one TensorFlow install and no leftovers:

bash
1python3 -m venv .venv
2source .venv/bin/activate
3python -m pip install --upgrade pip setuptools wheel
4python -m pip install tensorflow
5python -c "import tensorflow as tf; print(tf.__version__)"

If you need GPU support, install only the TensorFlow version that matches the CUDA and cuDNN runtime required by that release. A mismatch in that stack can surface as a missing .so during import.

Diagnose Linker Resolution

When the file exists but import still fails, inspect its dependencies:

bash
ldd /path/to/site-packages/tensorflow/libtensorflow_framework.so

Any dependency marked not found is the real problem. On Linux that can be a C++ runtime library, a CUDA component, or another shared object that TensorFlow expects to see.

As a diagnostic step, you can expose the package directory explicitly:

bash
export LD_LIBRARY_PATH="/path/to/site-packages/tensorflow:${LD_LIBRARY_PATH}"
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.constant([1, 2, 3])))"

If that works, the linker path is the issue. Treat this as confirmation, not as the preferred permanent fix.

Minimal Runtime Check

Once import succeeds, run a tiny program to confirm TensorFlow can execute kernels:

python
1import tensorflow as tf
2
3print("TensorFlow version:", tf.__version__)
4
5x = tf.constant([[1.0, 2.0], [3.0, 4.0]])
6y = tf.constant([[5.0], [6.0]])
7print(tf.matmul(x, y).numpy())

If this script works, the environment is healthy enough to return to your project.

Common Pitfalls

One common mistake is adding random symlinks until the error message changes. That can hide the original problem and replace it with an ABI mismatch that is harder to diagnose.

Another mistake is mixing package managers. A pip TensorFlow inside a Conda-managed Python, or a copied virtual environment from another machine, often leaves the runtime in a half-valid state.

A third pitfall is assuming the missing file is always TensorFlow's fault. In many cases the TensorFlow wheel is correct, but the host is missing a dependency or launches Python with a restricted environment.

Summary

  • This error means the operating system cannot load TensorFlow's native shared library.
  • Start by verifying the active Python executable and installed package path.
  • Reinstall in a clean virtual environment before attempting ad hoc fixes.
  • Use ldd to find the real missing dependency when the .so file exists.
  • Confirm the repair with a small TensorFlow script before returning to model code.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free 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