Skip to main content

How to Install PyTorch with uv

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

PyTorch installs like any other Python package, under the name torch. What you get depends on your computer: the build on PyPI uses the GPU of an Apple silicon Mac, NVIDIA GPUs on Linux, and only the processor on Windows. This guide installs PyTorch 2.15.0 with uv on an Apple M1 Pro and checks that it works.

Syntax​

Syntax
uv add torch
PartWhat it means
uv addAdds a package to the project: it writes it into pyproject.toml, records the exact versions in uv.lock and installs them into the project's .venv folder
torchPyTorch's package name. The name pytorch is a different package that only stops with an error

uv is a fast Python package and project manager. How to Add a Package to a Python Project with uv explains uv add in general.

The Example​

A new project named hello-pytorch gets PyTorch, then prints PyTorch's version to show the install works.

Prerequisites​

  • uv. This guide uses uv 0.13.10 with Python 3.15.2. PyTorch 2.15.0 needs Python 3.11 or later.
  • A Mac with Apple silicon on macOS 14 or later, a Windows PC or a Linux computer. PyTorch 2.15.0 has no build for Macs with an Intel processor.

Step 1: Create the Project​

Terminal
uv init --python 3.15 hello-pytorch
cd hello-pytorch
Output
Initialized project `hello-pytorch` at `/Users/you/source/hello-pytorch`

The terminal after uv init --python 3.15 hello-pytorch: Initialized project hello-pytorch.

--python 3.15 sets the Python version the project uses. How to Create a Python Project with uv explains the files uv init makes.

Step 2: Add PyTorch​

Terminal
uv add torch
Output
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
Creating virtual environment at: .venv
Resolved 28 packages in 840ms
Built hello-pytorch @ file:///Users/you/source/hello-pytorch
Prepared 11 packages in 12.95s
Installed 11 packages in 190ms
+ filelock==4.3.2
+ fsspec==2026.9.0
+ hello-pytorch==0.1.0 (from file:///Users/you/source/hello-pytorch)
+ jinja2==3.1.6
+ markupsafe==3.0.4
+ mpmath==1.3.0
+ networkx==3.7
+ setuptools==84.2.1
+ sympy==1.14.0
+ torch==2.15.0
+ typing-extensions==4.16.0

The terminal after uv add torch: uv creates the virtual environment, resolves 28 packages, downloads 11 in about 13 seconds and installs them, among them torch 2.15.0.

uv made the project's virtual environment, .venv, and installed PyTorch 2.15.0 with the packages it needs. It resolved 28 packages but installed 11: the lockfile covers every operating system, and the other 17 are NVIDIA's CUDA libraries and Triton, which only Linux installs. The download took about 13 seconds, and .venv came to 639 MB on this Mac.

What PyTorch can run on depends on the build PyPI has for your system. The uv guide to PyTorch says PyPI "hosts CPU-only wheels for Windows and macOS, and GPU-accelerated wheels on Linux". The lockfile shows what that meant for PyTorch 2.15.0:

Your computerThe torch build from PyPIDownload
Mac with Apple siliconRuns on the GPU through MPS (no CUDA, which Macs don't have)138.6 MB
Linux on x86-64Runs on NVIDIA GPUs: it also installs NVIDIA's CUDA 13.2 libraries539.2 MB, plus the CUDA libraries
WindowsRuns on the processor only126.7 MB

On Windows with an NVIDIA GPU, install the CUDA build from PyTorch's own index instead, as How to Install PyTorch with CUDA Using uv shows. I ran this guide on a Mac only.

Step 3: Check It​

Terminal
uv run python -c "import torch; print(torch.__version__)"
Output
/Users/you/source/hello-pytorch/.venv/lib/python3.15/site-packages/torch/_subclasses/functional_tensor.py:377: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /Users/runner/work/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:82.)
cpu = _conversion_method_template(device=torch.device("cpu"))
2.15.0

The terminal after the version check: a UserWarning that NumPy failed to initialize, then 2.15.0.

uv run runs the command inside the project's environment, and python -c runs the code in the quotes. PyTorch imported and reported 2.15.0. This first run took about 11 seconds. The command works unchanged in PowerShell.

The warning comes from PyTorch looking for NumPy, which uv add torch doesn't install. Nothing is broken, but most PyTorch code uses NumPy sooner or later.

Step 4: Add NumPy and Check Again​

Terminal
uv add numpy
uv run python -c "import torch; print(torch.__version__)"
Output
Resolved 29 packages in 649ms
Built hello-pytorch @ file:///Users/you/source/hello-pytorch
Prepared 2 packages in 926ms
Uninstalled 1 package in 1ms
Installed 2 packages in 10ms
~ hello-pytorch==0.1.0 (from file:///Users/you/source/hello-pytorch)
+ numpy==2.5.5
2.15.0

The terminal after uv add numpy and the version check: numpy 2.5.5 installed, then 2.15.0 with no warning.

With NumPy 2.5.5 installed, the warning is gone. Fixed: UserWarning: Failed to initialize NumPy: No module named 'numpy' explains the warning in full.

Common Mistakes​

MistakeWhat happensDo this instead
uv add pytorchThe build fails with Exception: You tried to install "pytorch". The package named for PyTorch is "torch"uv add torch; the fix in full
Expecting CUDA from uv add torch on WindowsPyPI's Windows build runs on the processor onlyUse PyTorch's CUDA index, as the link in Step 2 shows
Running python3 instead of uv run pythonModuleNotFoundError: No module named 'torch': the system Python doesn't see the project's .venvUse uv run

FAQ​

Do I also need torchvision?​

Only for images. torchvision adds image datasets, transforms and pretrained models. Add it the same way: uv add torchvision. PyTorch's own install command adds both.

How do I know whether PyTorch can use my GPU?​

Ask it: How to Check Whether PyTorch Can Use a GPU (CUDA or Apple MPS) shows the checks.

Why was the first run slower?​

The first import of PyTorch in a new environment took about 11 seconds here, the next one about 2. Every new project's environment pays it once.

Conclusion​

uv add torch installed PyTorch 2.15.0 and 10 other packages into a new project's .venv, 639 MB on an Apple M1 Pro. The version check printed 2.15.0, and uv add numpy cleared the warning PyTorch printed without NumPy.

Additional Resources​