Installing TensorFlow
TensorFlow is an open-source library from Google that builds and trains neural networks, and Keras is its high-level API for stacking layers, compiling a model and fitting it to data.
Last updated: 05 Oct, 2026 · TensorFlow 2 / Keras
The course runs on a small stack: TensorFlow 2.21 with Keras 3 for the practicals, NumPy for the worked examples, pandas and scikit-learn to prepare data, and matplotlib for plots. There are no API keys, and no lesson needs a GPU. You can install it on Windows, macOS or Linux, or skip the install and use Google Colab in a browser.
Checking your Python version
TensorFlow 2.21.0 publishes builds for Python 3.10 to 3.13, and NumPy 2.5 needs 3.12 or newer, so the course needs Python 3.12 or 3.13. Open a terminal (on Windows, PowerShell from the Start menu; on macOS, the Terminal app) and ask Python for its version:
python3 --version- 3.12.x or 3.13.x: you are set.
- 3.14: newer than TensorFlow 2.21 supports. Keep it, and let the uv route below install 3.12 for this project.
- 3.11 or lower, or "command not found": install Python 3.12 from python.org (on Windows, tick Add python.exe to PATH), or take the uv route, which downloads it for you.
TensorFlow 2.21 also needs a 64-bit machine it has a build for: Linux on x86-64 or ARM64, Windows on x86-64, or macOS 12 or later on Apple Silicon (M1 and newer). Intel Macs have no TensorFlow build after 2.16.2; on one, use Colab.
Installing the libraries
Pick one route. The uv route is the one to prefer on your own computer: it makes a project folder with its own environment and the right Python, so these pins never clash with other work. The pip route does the same with Python's built-in venv. Colab needs no install. The versions are pinned so your NumPy outputs match the lessons; JupyterLab is unpinned.
curl -LsSf https://astral.sh/uv/install.sh | sh
uv init dl-course --python 3.12
cd dl-course
uv add tensorflow==2.21.0 keras==3.15.1 numpy==2.5.3 pandas==3.0.6 scikit-learn==1.9.1 matplotlib==3.11.2 jupyterlabWhat the uv route sets up
- The first line installs uv, a fast Python package manager. Open a new terminal afterwards so the
uvcommand is found. uv init dl-course --python 3.12creates the folderdl-coursewith apyproject.tomlthat lists the project's libraries, and pins it to Python 3.12. uv downloads that Python the first time it needs it, if your computer lacks it.uv addcreates an environment indl-course/.venv, installs the libraries into it and records every exact version inuv.lock. TensorFlow is a large download, several hundred megabytes with its dependencies, so the first run takes a few minutes.- Run code with
uv run, for exampleuv run python check_tensorflow.py. There is no activation step.
What the pip and Colab routes do
python3 -m venv .venvmakes a private environment in the current folder, andactivateswitches the terminal to it: the prompt shows(.venv). Activate it again in every new terminal.py -3.12on Windows picks Python 3.12 when several versions are installed.- Colab already ships TensorFlow, and its version is whatever Google installed this month. That is fine for every lesson. If you install the pins, restart the session so the new versions load.
Using a GPU
Every lesson runs on a CPU. A GPU speeds up training of large networks, such as the CNN practical, and the route depends on your machine:
- NVIDIA GPU on Linux: install the extra CUDA libraries with TensorFlow,
python -m pip install "tensorflow[and-cuda]==2.21.0"(oruv add "tensorflow[and-cuda]==2.21.0"). The CUDA libraries are a much larger download than TensorFlow itself. You need the NVIDIA driver;nvidia-smiin a terminal shows whether it is there. The quotes stop zsh and bash from reading the square brackets as a file pattern. - NVIDIA GPU on Windows: TensorFlow 2.10 was the last release with GPU support on native Windows. Install WSL2 with Ubuntu (Windows 10 version 21H2 or later, or Windows 11), then follow the Linux route inside it. Native Windows still runs TensorFlow on the CPU.
- Apple Silicon: TensorFlow 2.21 runs on the CPU. The GPU plug-in
tensorflow-metalis at 1.2.0, publishes builds only up to Python 3.12, and its compatibility table stops at TensorFlow 2.18. For the Mac GPU, keep a separate project pinned to those versions (below); its outputs may differ slightly from the course's. - Colab: Runtime, Change runtime type, then pick a GPU such as the T4. Free GPU time is limited and not always available.
uv init dl-metal --python 3.12
cd dl-metal
uv add tensorflow==2.18.1 tensorflow-metal==1.2.0Writing code in Jupyter or VS Code
The video writes its practicals in a notebook: code in cells, each cell's output right under it. Start JupyterLab from the project folder and it opens in your browser:
uv run jupyter labIn JupyterLab, choose File, New, Notebook, pick the Python 3 kernel, and paste a lesson's code into a cell. In VS Code, install the Python and Jupyter extensions, open the project folder, run Python: Select Interpreter from the Command Palette and choose the one in .venv. A .ipynb file then runs in VS Code, and a .py file runs with the Run button.
Checking TensorFlow
Save this as check_tensorflow.py and run it with uv run python check_tensorflow.py, or python check_tensorflow.py with the venv active, or paste it into a notebook cell:
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" # hide start-up info and warning lines
import sys
import tensorflow as tf
import keras
print("Python ", sys.version.split()[0])
print("tensorflow", tf.__version__)
print("keras ", keras.__version__)
print("GPUs ", tf.config.list_physical_devices("GPU"))
print("a sum ", float(tf.reduce_sum(tf.ones((2, 3)))))It prints five lines. The first three should read Python 3.12.x (or 3.13.x), tensorflow 2.21.0 and keras 3.15.1, or Colab's own versions there. The GPU line is an empty list [] on a machine without a working GPU, and a list with one PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU') entry per GPU when CUDA, Metal or a Colab GPU is set up. The last line is 6.0, the sum of a 2 × 3 tensor of ones, which proves TensorFlow can compute.
Checking NumPy and the data libraries
The worked examples in every theory lesson need only NumPy. This check prints the other versions too and computes a first weighted sum, the student with IQ 95, 4 study hours and 4 play hours from the forward pass in the notes:
import sys
import numpy as np, pandas as pd, sklearn, matplotlib
print("Python ", sys.version.split()[0])
print("numpy ", np.__version__)
print("pandas ", pd.__version__)
print("scikit-learn", sklearn.__version__)
print("matplotlib ", matplotlib.__version__)
x = np.array([95, 4, 4]) # IQ, study hours, play hours
w = np.array([0.01, 0.02, 0.03]) # one weight per input
print("weighted sum", round(float(x @ w + 0.001), 3)) # + the bias 0.001Python 3.12.13 numpy 2.5.3 pandas 3.0.6 scikit-learn 1.9.1 matplotlib 3.11.2 weighted sum 1.151
Reading the version checks
- Python 3.12 or 3.13 is the range that fits both TensorFlow 2.21 and NumPy 2.5.
- numpy 2.5.3 is the version every NumPy output in these lessons comes from; pandas, scikit-learn and matplotlib match the pins.
- 1.151 is the weighted sum 95 × 0.01 + 4 × 0.02 + 4 × 0.03 + 0.001. Forward propagation carries it through a sigmoid to a prediction.
Fixing a failed install
Most install problems print one of a few messages. Find yours:
ERROR: Could not find a version that satisfies the requirement tensorflow==2.21.0, thenNo matching distribution found: there is no TensorFlow build for this Python or this machine. Usually the Python is too new (3.14) or too old; the brackets after it may list only a pre-release. Check the version, then useuv init --python 3.12or a 3.12 install. On an Intel Mac the same message means no build exists; use Colab.No matching distribution found for numpy==2.5.3: the Python running pip is older than 3.12.pip install tensorflow-gpufails withFailed to build 'tensorflow-gpu' when getting requirements to build wheel: no new versions have been released since December 2022, and the newest one on PyPI is an empty package that stops the install. Installtensorflow, which has GPU support itself, plus[and-cuda]on Linux.zsh: no matches found: tensorflow[and-cuda]==2.21.0: put the package name in quotes,"tensorflow[and-cuda]==2.21.0".No matching distribution found for tensorflow-metal==1.2.0on a Mac: the plug-in has no Python 3.13 build; make its project with--python 3.12.error: externally-managed-environment: this Python belongs to the operating system or Homebrew, which blocks pip. Use a venv or the uv route..venv\Scripts\activatefails in PowerShell withrunning scripts is disabled on this system: allow local scripts once withSet-ExecutionPolicy -Scope CurrentUser RemoteSigned, then activate again. The uv route needs no activation.ModuleNotFoundError: No module named 'tensorflow': the code runs with a different Python from the one you installed into. Run it withuv run, activate the venv, or select the.venvinterpreter in VS Code.- Lines like
oneDNN custom operations are onorCould not find cuda drivers on your machine, GPU will not be usedwhen TensorFlow loads: these are information messages, not errors. The second one means TensorFlow runs on the CPU.TF_CPP_MIN_LOG_LEVELin the check script hides them. - Colab still prints the old version after
%pip install: the session was not restarted.
uv vs pip vs Colab
| uv | pip with venv | Colab | |
|---|---|---|---|
| Where it runs | Your computer | Your computer | A browser, on Google's machines |
| Installs Python for you | Yes | No | Python is already there |
| Keeps versions per project | Yes, in pyproject.toml and uv.lock | Yes, in .venv, but no lock file | Per session; reinstall after a reset |
| GPU | Your own (NVIDIA on Linux or WSL2) | Your own (NVIDIA on Linux or WSL2) | Free T4 when available |
| Good for | Repeatable projects | A familiar, standard setup | No local install, or an Intel Mac |
Where you use each setup
- Following the theory lessons: any route works, since the worked examples need only NumPy.
- The ANN and CNN practicals: TensorFlow on your machine, or Colab with a GPU runtime for the CNN, the way the video runs them.
- Your own project: the uv route records the exact versions, so a teammate gets the same install with
uv sync.
tf.keras is Keras 3. Most of the old code still runs, but some arguments now warn or have moved; the practical lessons name each change under the code. When an output differs from a lesson, print tf.__version__ and keras.__version__ first.Related
- Previous: Why deep learning is popular
- Next: Perceptron
- Reference: Install TensorFlow with pip, the uv documentation and tensorflow-metal on PyPI
- Run the install guide's own check:
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))". It prints a tensor with a random sum; any number means TensorFlow works. - In the NumPy check, change the weights to
[0.02, 0.02, 0.02]and predict the new weighted sum before you run it. - In Colab, switch the runtime to a GPU, run
check_tensorflow.pyin a cell again, and watch the GPU line change from[]to one device.
Slow is fine. Stopping is the only problem.