TensorFlow
Anaconda
Ubuntu
Machine Learning
Python

Tensorflow and Anaconda on Ubuntu?

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

TensorFlow works well on Ubuntu with Anaconda, but the clean setup pattern is important: use conda for environment isolation and use either pip or conda packages consistently inside that environment. Most installation pain comes from mixing package managers carelessly or from assuming the wrong Python interpreter is active.

Create an Isolated Conda Environment

Start by creating a dedicated environment for TensorFlow instead of installing into base.

bash
conda create -n tf-env python=3.10
conda activate tf-env

This isolates TensorFlow and its dependencies from unrelated scientific packages. It also makes rollback easy because you can delete and recreate the environment instead of repairing a polluted global setup.

Install TensorFlow Inside the Environment

A common modern approach is to use pip inside the conda environment:

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

This pattern is practical because TensorFlow wheels are published through the normal Python packaging ecosystem, while conda still provides the environment and interpreter management.

The important point is not whether you are loyal to one tool. The important point is that the environment is isolated and reproducible.

Verify the Installation Immediately

After installation, test both Python and TensorFlow from inside the activated environment.

bash
python -c "import sys, tensorflow as tf; print(sys.executable); print(tf.__version__)"

This confirms two things:

  • Which interpreter is actually running.
  • Whether TensorFlow imports successfully.

If the interpreter path does not point into your conda environment, the shell session is not using the environment you think it is.

A Small Runtime Check

A small numerical check is worth running after import succeeds.

python
1import tensorflow as tf
2
3x = tf.constant([[1.0, 2.0], [3.0, 4.0]])
4y = tf.constant([[5.0, 6.0], [7.0, 8.0]])
5
6print(tf.matmul(x, y))

If that works, the package is not just installed. It is operational.

Why Anaconda Is Useful Here

Anaconda does not make TensorFlow itself smarter. Its real value is environment management:

  • Separate interpreters for different projects.
  • Easy package isolation.
  • Reproducible environment exports.
  • Cleaner coexistence with other data-science stacks.

On Ubuntu, that is especially useful when you have multiple machine-learning projects that need different package versions.

Export the Working Environment

Once the setup works, export it:

bash
conda env export --no-builds > environment.yml

This makes it easier to recreate the environment later or share it with teammates. It also gives you a stable snapshot before you start adding more packages.

GPU Expectations Need Separate Attention

If your goal is GPU acceleration, the package install is only part of the story. Driver compatibility and the machine's CUDA-capable stack matter too. That is why CPU-only import success does not automatically prove GPU support is configured correctly.

A quick check inside Python:

python
import tensorflow as tf
print(tf.config.list_physical_devices("GPU"))

If the list is empty, do not immediately blame Anaconda. The issue may be lower in the system stack.

Common Pitfalls

  • Installing TensorFlow into the conda base environment.
  • Mixing conda and pip packages randomly until dependency state becomes inconsistent.
  • Forgetting to verify the active interpreter path after activation.
  • Treating a successful import as proof that GPU support is configured.
  • Adding many other packages before exporting a known-good environment.

Summary

  • On Ubuntu, Anaconda is best used as environment management around TensorFlow.
  • Create a dedicated conda environment instead of using base.
  • Install TensorFlow inside that environment and verify the active interpreter immediately.
  • Export the environment once it works so it can be recreated cleanly.
  • If GPU support is the goal, validate the system stack separately from the Python package install.

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

All Rights Reserved.