Skip to content

How to Install TensorFlow with uv

Install TensorFlow for CPU use in an existing uv project. Run the commands from the project directory.

Prerequisites

On Windows x86-64, install the Microsoft Visual C++ Redistributable 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:

uv python pin 3.13
uv add tensorflow

The first command prints Pinned `.python-version` to `3.13` (or 3.12). The installation summary includes:

+ tensorflow==2.21.0

On Intel Macs:

+ tensorflow==2.16.2

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

Verify the installation

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:

TensorFlow 2.21.0; [[5.0]]

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

Last updated on