Install TensorFlow Python Library on Ubuntu

In this tutorial, we shall learn how to install TensorFlow Python library on Ubuntu using pip. TensorFlow is a machine learning and deep learning library used for building and running models in Python. The current recommended approach for most Ubuntu users is to create a clean Python environment, upgrade pip, install TensorFlow from PyPI, and verify the installation with a small Python command.

The older version of this tutorial used Anaconda and installed TensorFlow 1.4.1. That output is kept later in this page only for historical reference. For a new setup, use the current TensorFlow 2 installation steps below.

TensorFlow Ubuntu Requirements Before Running pip Install

Before installing TensorFlow on Ubuntu, check the Python version, pip version, CPU or GPU requirement, and whether you want a system Python virtual environment or an Anaconda environment. TensorFlow packages are version-sensitive, so an unsupported Python version is one of the most common causes of installation errors.

  • Operating system: Use a 64-bit Ubuntu installation for the standard Linux TensorFlow package.
  • Python version: Use a TensorFlow-supported 64-bit Python version. Python 3.10, 3.11, or 3.12 is a practical choice for most current Ubuntu setups. If you use a newer Python release, confirm support on the official TensorFlow install page first.
  • pip: Upgrade pip before installing TensorFlow, because older pip versions may not recognize current wheel formats.
  • CPU or GPU: A CPU-only installation is simpler. NVIDIA GPU support requires compatible drivers and the correct TensorFlow GPU package option.
  • Environment: Use a virtual environment so TensorFlow dependencies do not conflict with packages installed for other Python projects.

For the latest official package notes, refer to the TensorFlow pip installation guide at tensorflow.org/install/pip. If you specifically want Anaconda first, you may start with Install Anaconda Python and then install TensorFlow with pip inside a conda environment.

Check Python and pip Versions on Ubuntu

Open Terminal and check the installed Python and pip versions. Use python3 -m pip instead of plain pip when you want to be sure that pip belongs to the same Python interpreter.

</>
Copy
python3 --version
python3 -m pip --version

Example output:

Python 3.11.9
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.11)

If Python is not installed, install Python, pip, and the virtual environment package using Ubuntu’s package manager.

</>
Copy
sudo apt update
sudo apt install python3 python3-pip python3-venv

Create a Python Virtual Environment for TensorFlow on Ubuntu

A virtual environment keeps TensorFlow and its dependencies separate from the system Python packages. This makes it easier to upgrade, remove, or recreate the TensorFlow setup later.

</>
Copy
mkdir -p ~/tensorflow-projects
cd ~/tensorflow-projects

python3 -m venv tf-env
source tf-env/bin/activate

After activation, the terminal prompt usually shows the environment name. Then upgrade pip inside this environment.

</>
Copy
python -m pip install --upgrade pip

Install TensorFlow on Ubuntu for CPU Using pip

For a normal CPU-based setup, install the stable TensorFlow package from PyPI with the following command.

</>
Copy
python -m pip install tensorflow

This command installs TensorFlow and its required Python dependencies in the active virtual environment. Use this method when you are learning TensorFlow, running examples, or developing models that do not require GPU acceleration.

Install TensorFlow with NVIDIA GPU Support on Ubuntu or WSL2

If your machine has a supported NVIDIA GPU, install the GPU-enabled TensorFlow package option. First check whether the NVIDIA driver is visible from Ubuntu.

</>
Copy
nvidia-smi

If the driver is installed and the GPU is listed, install TensorFlow with the CUDA extra:

</>
Copy
python -m pip install "tensorflow[and-cuda]"

GPU setup is more sensitive than CPU setup because driver, CUDA, cuDNN, Python, and TensorFlow versions must be compatible. If you do not specifically need GPU acceleration, start with the CPU installation first and move to GPU only after the basic TensorFlow import works.

Verify TensorFlow Installation in Python

After installation, verify that Python can import TensorFlow and print the installed version.

</>
Copy
python -c "import tensorflow as tf; print(tf.__version__)"

You can also run a small tensor operation to confirm that TensorFlow is working.

</>
Copy
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

Example output will vary because the tensor contains random values.

tf.Tensor(-823.45764, shape=(), dtype=float32)

For a GPU installation, check whether TensorFlow can see the GPU devices.

</>
Copy
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

If the command prints an empty list, TensorFlow is installed, but it is not detecting a GPU. Check the NVIDIA driver, WSL2 configuration if applicable, and the TensorFlow GPU installation notes.

Install TensorFlow in an Anaconda Environment on Ubuntu

You can still use Anaconda or Miniconda to manage the Python environment, but install TensorFlow itself using pip inside the conda environment. This keeps the environment isolated while still using the TensorFlow package published to PyPI.

</>
Copy
conda create --name tf python=3.11
conda activate tf
python -m pip install --upgrade pip
python -m pip install tensorflow

If you already followed the Anaconda setup tutorial, activate the conda environment first and then run the TensorFlow pip install command. Avoid mixing many unrelated machine learning packages in the same environment, because dependency conflicts become harder to debug.

Original TensorFlow 1.x pip Command Kept for Reference

The command and terminal output below are from the older version of this tutorial. They show TensorFlow 1.4.1 being installed in a Python 3.6 Anaconda setup. Do not use this output to check a current installation, because modern TensorFlow installations use newer TensorFlow 2 packages and different dependencies.

$ pip install tensorflow

Console/Terminal Output

~$ pip install tensorflow
Collecting tensorflow
  Downloading tensorflow-1.4.1-cp36-cp36m-manylinux1_x86_64.whl (41.2MB)
    100% |????????????????????????????????| 41.2MB 20kB/s 
Requirement already satisfied: numpy>=1.12.1 in /usr/lib/anaconda3/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: six>=1.10.0 in /usr/lib/anaconda3/lib/python3.6/site-packages (from tensorflow)
Requirement already satisfied: wheel>=0.26 in /usr/lib/anaconda3/lib/python3.6/site-packages (from tensorflow)
Collecting protobuf>=3.3.0 (from tensorflow)
  Downloading protobuf-3.5.0.post1-cp36-cp36m-manylinux1_x86_64.whl (6.4MB)
    100% |????????????????????????????????| 6.4MB 80kB/s 
Collecting enum34>=1.1.6 (from tensorflow)
  Downloading enum34-1.1.6-py3-none-any.whl
Collecting tensorflow-tensorboard<0.5.0,>=0.4.0rc1 (from tensorflow)
  Downloading tensorflow_tensorboard-0.4.0rc3-py3-none-any.whl (1.7MB)
    100% |????????????????????????????????| 1.7MB 108kB/s 
Requirement already satisfied: setuptools in /usr/lib/anaconda3/lib/python3.6/site-packages (from protobuf>=3.3.0->tensorflow)
Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading html5lib-0.9999999.tar.gz (889kB)
    100% |????????????????????????????????| 890kB 153kB/s 
Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
  Downloading Markdown-2.6.10.zip (414kB)
    100% |????????????????????????????????| 419kB 220kB/s 
Requirement already satisfied: werkzeug>=0.11.10 in /usr/lib/anaconda3/lib/python3.6/site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow)
Building wheels for collected packages: html5lib, markdown
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: /home/arjun/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
  Running setup.py bdist_wheel for markdown ... done
  Stored in directory: /home/arjun/.cache/pip/wheels/1e/5a/55/a80b200d12e234d575ad68c1528593d1ce488720b65b24e48c
Successfully built html5lib markdown
Installing collected packages: protobuf, enum34, html5lib, bleach, markdown, tensorflow-tensorboard, tensorflow
  Found existing installation: html5lib 0.999999999
    Uninstalling html5lib-0.999999999:
      Successfully uninstalled html5lib-0.999999999
  Found existing installation: bleach 2.0.0
    Uninstalling bleach-2.0.0:
      Successfully uninstalled bleach-2.0.0
Successfully installed bleach-1.5.0 enum34-1.1.6 html5lib-0.9999999 markdown-2.6.10 protobuf-3.5.0.post1 tensorflow-1.4.1 tensorflow-tensorboard-0.4.0rc3

Fix TensorFlow pip Install Errors on Ubuntu

Most TensorFlow installation errors on Ubuntu are caused by Python version mismatch, old pip, inactive virtual environments, or GPU library conflicts. The table below shows common symptoms and practical checks.

TensorFlow install problemLikely reasonWhat to check on Ubuntu
No matching distribution found for tensorflowUnsupported Python version, unsupported architecture, or old pip.Run python3 --version and python3 -m pip --version. Use a supported 64-bit Python release and upgrade pip.
TensorFlow installs but import failsBroken dependency, mixed environments, or incompatible package versions.Create a fresh virtual environment and reinstall TensorFlow with python -m pip install tensorflow.
pip installs packages outside the environmentThe virtual environment is not activated or the wrong pip command is used.Activate the environment and use python -m pip instead of a global pip command.
GPU is not detectedNVIDIA driver or CUDA-related setup is missing or incompatible.Run nvidia-smi and then verify with tf.config.list_physical_devices('GPU').
Permission denied during pip installTrying to install into system Python without permission.Use a virtual environment instead of running pip with sudo.

TensorFlow Installation Choices for Ubuntu Beginners

There are several ways to start using TensorFlow. Choose the setup based on what you need to do.

Setup optionBest forNotes
pip with venv on UbuntuMost beginners and local Python projects.Simple, clean, and close to the official TensorFlow pip workflow.
pip inside conda environmentUsers who already manage Python through Anaconda or Miniconda.Use conda for the environment and pip for TensorFlow.
TensorFlow GPU on UbuntuTraining larger models on a supported NVIDIA GPU.Requires more careful driver and compatibility checks.
TensorFlow Docker imageReproducible environments, servers, and experiments that should not affect the host Python setup.Useful when you want a containerized environment.
Google ColabLearning TensorFlow without installing anything locally.Runs in the browser and is useful for notebooks and quick practice.

TensorFlow Ubuntu Installation QA Checklist

  • Does the tutorial tell the reader to check Python and pip versions before installing TensorFlow?
  • Does the CPU install path use a virtual environment and python -m pip install tensorflow?
  • Does the GPU section clearly separate NVIDIA GPU setup from the simpler CPU setup?
  • Does the Anaconda section explain that TensorFlow should be installed with pip inside the conda environment?
  • Does the verification section test both TensorFlow import and GPU detection where needed?
  • Does the troubleshooting section address Python version mismatch, old pip, wrong environment, and GPU detection errors?

TensorFlow Installation on Ubuntu FAQs

How do I install TensorFlow on Linux Ubuntu?

Create a Python virtual environment, activate it, upgrade pip, and run python -m pip install tensorflow. Then verify the installation with python -c "import tensorflow as tf; print(tf.__version__)".

How do I pip install TensorFlow correctly?

Use python -m pip install tensorflow from inside the active Python environment. This is safer than plain pip install tensorflow because it uses the pip module that belongs to the currently selected Python interpreter.

Is TensorFlow a deep learning library?

Yes. TensorFlow is commonly used for deep learning and machine learning tasks such as neural networks, image classification, natural language processing, recommendation models, and numerical computation workflows.

What is the best Ubuntu version for TensorFlow?

Use a supported 64-bit Ubuntu release that can run a TensorFlow-supported Python version and a recent pip version. For new setups, a current Ubuntu LTS release is usually easier to maintain than an older Ubuntu release.

Should I install TensorFlow with conda or pip?

Use pip to install TensorFlow. If you prefer Anaconda, create and activate a conda environment first, then install TensorFlow inside that environment using python -m pip install tensorflow.

Conclusion: TensorFlow Python Library Installed on Ubuntu

TensorFlow Python library is successfully installed when Python can import TensorFlow and print a version number or tensor result. For most Ubuntu users, the cleanest setup is a Python virtual environment with upgraded pip and the command python -m pip install tensorflow. Use the GPU install option only when you have a supported NVIDIA GPU and need acceleration for model training or inference.