# How to Install TensorFlow with uv


Install TensorFlow for CPU use in an existing [uv](https://pydevtools.com/handbook/reference/uv.md) project. Run the commands from the project directory.

## Prerequisites

On Windows x86-64, install the [Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist) first.

If `requires-python` in `pyproject.toml` excludes the selected Python, update it first: `">=3.13"` for the first tab or `">=3.12"` for Intel Macs. Lower the minimum only if the application supports it.

## Install for your platform

Intel Macs require an older TensorFlow release. Choose the matching tab:

```bash
uv python pin 3.13
uv add tensorflow
```
```bash
uv python pin 3.12
uv add "tensorflow<2.17"
```
The first command prints ``Pinned `.python-version` to `3.13` `` (or `3.12`). The installation summary includes:

```text
+ tensorflow==2.21.0
```

On Intel Macs:

```text
+ tensorflow==2.16.2
```

uv records Python in `.python-version`, adds TensorFlow to `pyproject.toml`, and locks dependencies in `uv.lock`.

## Verify the installation

```bash
uv run python -c "import tensorflow as tf; x=tf.constant([[1.0, 2.0]]); y=tf.matmul(x, tf.transpose(x)); assert y.numpy().tolist() == [[5.0]]; print(f'TensorFlow {tf.__version__}; {y.numpy().tolist()}')"
```

`uv run` executes the command inside the project's virtual environment, ensuring all dependencies are installed first. After any CPU capability messages, expect:

```text
TensorFlow 2.21.0; [[5.0]]
```

Intel Macs print `TensorFlow 2.16.2; [[5.0]]`.
