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 2: Check your Python version

Apple Silicon Macs with macOS 12 (Monterey) or later can run TensorFlow with Python 3.10–3.13. Check what you have:

python3 --version

If you need a specific Python version, I recommend installing it through Homebrew:

brew install python@3.11

Step 3: Create a virtual environment

python3 -m venv ~/tf_env
source ~/tf_env/bin/activate

Step 4: Upgrade pip

pip install --upgrade pip

Step 5: Install TensorFlow

For Apple Silicon on TensorFlow 2.13 and later, you can use the standard package:

pip install tensorflow

For older TensorFlow versions on Apple Silicon (below 2.13), you needed separate packages:

pip install tensorflow-macos
pip install tensorflow-metal # for GPU acceleration via Metal API

If you’re starting fresh today, just use pip install tensorflow — it handles Apple Silicon natively.

Step 6: Verify

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

How to Install TensorFlow Using Conda

If you’re using Anaconda or Miniconda (common in data science workflows), here’s how I’d do it:

Step 1: Create a new conda environment with Python 3.11

conda create -n tf_env python=3.11

Step 2: Activate it

conda activate tf_env

Step 3: Install TensorFlow using pip (not conda install)

pip install tensorflow

⚠️ Important: Use pip install tensorflow even inside a conda environment. The conda install tensorflow package on conda-forge is often out of date. Mixing conda’s TF package with pip packages also causes dependency conflicts. Stick with pip for TensorFlow.

Step 4: Verify

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

How to Verify TensorFlow is Working Correctly

Once installed, run this script to confirm everything is set up properly. It checks your TF version and whether a GPU is detected:

import tensorflow as tf

print("TensorFlow version:", tf.__version__)
print("GPU devices available:", tf.config.list_physical_devices('GPU'))
print("Number of GPUs:", len(tf.config.list_physical_devices('GPU')))

Refer to the screenshot below for the output.

How to Install Python TensorFlow

What to expect:

  • If you’re on CPU only, GPU devices available will return an empty list [] — that’s completely normal
  • If you have a compatible GPU and installed the CUDA-enabled version, you’ll see your GPU listed here

Your First TensorFlow Program — Sanity Check

Let me give you a quick working example to confirm TensorFlow is truly working end-to-end. This creates a simple neural network and trains it on dummy data:

import tensorflow as tf
import numpy as np

# Create some dummy data
X = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=float)
y = np.array([2.0, 4.0, 6.0, 8.0, 10.0], dtype=float) # y = 2x

# Build a simple model
model = tf.keras.Sequential([
tf.keras.layers.Dense(units=1, input_shape=[1])
])

# Compile it
model.compile(optimizer='sgd', loss='mean_squared_error')

# Train it
model.fit(X, y, epochs=200, verbose=0)

# Make a prediction
prediction = model.predict([6.0])
print(f"Prediction for input 6: {prediction[0][0]:.2f}") # Should be close to 12.0

If this runs without errors and prints a number close to 12.00, your TensorFlow setup is solid.

Common TensorFlow Installation Errors and How to Fix Them

These are the errors I see most often. If you’re stuck, your answer is probably here.

Error 1: Could not find a version that satisfies the requirement tensorflow

Why it happens: Your Python version is not supported by TensorFlow. This is the #1 installation error, and it’s almost always a Python version mismatch.

How to fix it:

  1. Check your Python version: python –version
  2. If you’re on Python 3.14 or 3.9 and below, create a new virtual environment with Python 3.11 or 3.12
  3. On Windows, download the correct Python version from python.org and set it up as a separate environment

Error 2: ModuleNotFoundError: No module named ‘tensorflow’

Why it happens: TensorFlow was installed in a different environment or globally, not inside your active virtual environment.

How to fix it:

  1. Make sure your virtual environment is activated first — look for (tf_env) in your prompt
  2. Run pip list | grep tensorflow (Linux/Mac) or pip list | findstr tensorflow (Windows) to confirm it’s installed in the active environment
  3. If it’s not there, run pip install tensorflow after activating

Error 3: ImportError: cannot import name ‘xxx’ from ‘tensorflow’

Why it happens: Version mismatch between TensorFlow and one of its dependencies (often NumPy or Keras).

How to fix it:

pip uninstall tensorflow
pip install tensorflow --upgrade
pip install numpy --upgrade

Check out: Build Your First Neural Network in TensorFlow

Error 4: DLL load failed while importing _pywrap_tensorflow_internal (Windows)

Why it happens: Missing Microsoft Visual C++ Redistributable runtime on Windows.

How to fix it:

  1. Go to Microsoft’s official page and download the latest Visual C++ Redistributable (x64)
  2. Install it and restart your computer
  3. Try pip install tensorflow again

Error 5: W tensorflow/core/platform/cpu_feature_guard.cc warnings on startup

These are not errors — they’re just informational warnings telling you that TensorFlow was compiled with additional CPU instruction support that could make it faster. You can safely ignore them, or suppress them by adding this before your imports:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf

Error 6: pip install tensorflow hangs or takes forever

Why it happens: Slow connection, pip cache issues, or a conflicting package resolution.

How to fix it:

pip install tensorflow --no-cache-dir

If you’re behind a corporate proxy or firewall, you may also need to configure pip’s proxy settings.

Frequently Asked Questions

Q: Do I need a GPU to use TensorFlow?

No, you don’t. TensorFlow works perfectly well on CPU. GPU training is significantly faster for large deep learning models, but for learning, smaller projects, or inference, CPU is absolutely fine.

Q: Can I install TensorFlow without a virtual environment?

Technically yes, but I’d strongly recommend against it. Installing packages globally will eventually cause version conflicts between different projects. Virtual environments take 30 seconds to set up and save you hours of debugging later.

Q: Is tensorflow-gpu still a separate package?

No. Since TensorFlow 2.0, GPU support is included in the standard pip install tensorflow package. You don’t need to install tensorflow-gpu anymore — that package is deprecated.

Q: Does TensorFlow work with Python 3.14?

Not yet. Python 3.14 support is not available in TensorFlow as of the current release. Use Python 3.11 or 3.12 for the most stable experience.

Q: How do I upgrade TensorFlow to the latest version?

pip install tensorflow –upgrade
Run this with your virtual environment activated. I’d also recommend testing your code after upgrading, as major versions occasionally have breaking API changes.

Q: Can I use TensorFlow on Jupyter Notebook?

Yes. After installing TensorFlow in your virtual environment, install Jupyter in the same environment:
pip install jupyter
jupyter notebook
Then use import tensorflow as tf in your notebook cells as normal.

Quick Reference: Installation Commands by Platform

PlatformCommand
Windows (CPU)pip install tensorflow
Linux CPUpip install tensorflow
Linux GPU (NVIDIA)pip install tensorflow[and-cuda]
macOS Intel (CPU)pip install tensorflow
macOS Apple Siliconpip install tensorflow
Conda (any platform)conda create -n tf_env python=3.11 → pip install tensorflow

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.