How to Install TensorFlow in Python (Windows, Linux & macOS)

I’ve set up TensorFlow on dozens of machines — fresh Windows laptops, Ubuntu servers, and M1/M2 Macs — and I can tell you that most people who run into trouble aren’t doing anything dramatically wrong. They’re just using the wrong Python version, skipping the virtual environment step, or following a guide that’s two years out of date.

This guide fixes all of that. I’ll walk you through installing TensorFlow on Windows, Linux (Ubuntu), and macOS — including Apple Silicon Macs — step by step, using a virtual environment the right way. I’ll also cover the most common errors you’ll hit and exactly how to fix them.

By the end, you’ll have a working TensorFlow setup you can immediately start using for your ML projects.

Table of Contents:

What is TensorFlow and Why Should You Care?

TensorFlow is an open-source machine learning framework built by Google. It powers a huge chunk of real-world AI applications — image recognition, natural language processing, recommendation engines, medical diagnostics, and more.

Here’s what makes it worth learning:

  • It runs everywhere: your laptop, a cloud server, a mobile phone, or even a browser
  • It has excellent support for both CPU and GPU training
  • It integrates tightly with Keras, making deep learning more accessible
  • There’s a massive community and tons of pre-built models you can fine-tune

If you’re getting into machine learning, computer vision, or deep learning in Python, TensorFlow is one of the first tools you’ll need in your toolkit.

Python Version Compatibility — Check This First

Before you even open a terminal, this is the most important thing to know: TensorFlow does not support every Python version. This is responsible for probably 80% of installation failures I’ve seen.

Here’s the current compatibility matrix as of TensorFlow 2.21.0 (the latest stable release):

TensorFlow VersionPython Versions SupportedNotes
2.21.0 (latest)3.10, 3.11, 3.12, 3.13Python 3.9 support dropped in this version
2.16.x3.9, 3.10, 3.11, 3.12Last x86 version with broad 3.9 support
2.15.x3.9, 3.10, 3.11Last version with TensorBoard bundled
2.10.x3.7, 3.8, 3.9, 3.10Last version with native GPU support on Windows

My recommendation: Use Python 3.11 or 3.12. They’re the sweet spot — well-tested, widely supported, and stable. Python 3.13 is technically supported on the latest builds, but is still relatively new, so you may hit occasional compatibility issues with other ML libraries like NumPy or SciPy.

⚠️ Important: Python 3.14 is not yet supported by TensorFlow. If you’re on 3.14, you’ll need to create a separate virtual environment using Python 3.11 or 3.12.

Before You Start: Prerequisites

Make sure you have the following in place before we begin:

  • Python 3.10–3.12 installed (check with python –version or python3 –version)
  • pip updated to the latest version (we’ll do this as part of the setup)
  • A stable internet connection
  • About 500MB–1GB of free disk space

That’s it. You don’t need CUDA or a GPU to follow this guide — TensorFlow’s standard install works perfectly on CPU only, which is fine for learning, experimenting, and smaller models.

How to Install TensorFlow on Windows

I’ll walk through this using a virtual environment. Skipping this step is the #1 mistake beginners make — without it, your packages start conflicting with each other over time, and things break in confusing ways.

Step 1: Check your Python version

Open Command Prompt or PowerShell and run:

python --version

Refer to the screenshot below for the output.

How to Install TensorFlow in Python

You should see Python 3.10, 3.11, or 3.12. If you see 3.9 or below, download a newer version from python.org.

Step 2: Upgrade pip

python -m pip install --upgrade pip

Always do this before installing anything. An outdated pip causes more mysterious errors than you’d expect.

Step 3: Create a virtual environment

Navigate to the folder where you want to keep your project, then run:

python -m venv tf_env

This creates a folder called tf_env with an isolated Python environment inside it.

Step 4: Activate the virtual environment

tf_env\Scripts\activate

Once activated, you’ll see (tf_env) at the start of your terminal prompt. This tells you you’re inside the environment, and any packages you install go here, not globally.

Check out: Use Keras in TensorFlow for Rapid Prototyping

Step 5: Install TensorFlow

pip install tensorflow

Refer to the screenshot below for the output.

Install TensorFlow in Python

That’s it. Since TensorFlow 2.0, both CPU and GPU support are bundled into a single package. You no longer need tensorflow-gpu as a separate install.

Step 6: Verify the installation

python -c "import tensorflow as tf; print(tf.__version__)"

If you see a version number like 2.21.0, you’re good to go.

How to Install TensorFlow on Linux (Ubuntu)

This process works on Ubuntu 22.04 and 24.04. Ubuntu 22.04 ships with Python 3.10 by default, and Ubuntu 24.04 ships with Python 3.12 — both are fully supported by TensorFlow 2.21.

Step 1: Make sure Python and pip are installed

python3 --version
sudo apt install python3-pip python3-venv -y

Step 2: Upgrade pip

python3 -m pip install --upgrade pip

Step 3: Create a virtual environment

python3 -m venv ~/tf_env

Step 4: Activate it

source ~/tf_env/bin/activate

Your prompt will change to (tf_env) to confirm it’s active.

Step 5: Install TensorFlow

pip install tensorflow

For GPU support on Linux (requires a compatible NVIDIA GPU with CUDA), use:

pip install tensorflow[and-cuda]

This installs TensorFlow along with the required CUDA libraries in one command — no manual CUDA setup needed.

Step 6: Verify

python3 -c "import tensorflow as tf; print(tf.__version__)"

Read: Debug TensorFlow Models: Best Practices

How to Install TensorFlow on macOS

Here, I will explain to you how to install Tensorflow on macOS.

Intel-based Macs (x86)

Intel Macs work the same way as the Linux process above. Just use python3 instead of python, and the standard pip install tensorflow command.

Note: TensorFlow does not support GPU acceleration on Intel-based Macs. CPU-only is your option here.

Apple Silicon Macs (M1, M2, M3, M4)

This is where things are slightly different. Apple Silicon uses the ARM64 architecture, and the setup requires a small extra step to enable GPU (Metal) acceleration through Apple’s own ML stack.

Step 1: Install Xcode Command Line Tools (if not already done)

xcode-select --install

Step