Skip to content

How-ToGPU

How to Use uv to Set Up Python for Local AI Apps on Windows

uv installs Python, creates a separate environment for every AI app and can pick the right GPU build of PyTorch for you. Here's how to set it up on Windows, using a manual ComfyUI install as the example.

By , Systems & Technical Editor

5 min read

How to Use uv to Set Up Python for Local AI Apps on Windows

If you've ever installed one local AI app and broken another, uv is the fix. It's a free tool from Astral that installs Python versions, creates a separate environment for each app and can pick the right GPU build of PyTorch for your graphics card. This guide shows how to install uv on Windows and use it for a manual ComfyUI install, a good worked example because ComfyUI publishes standard pip instructions. The same steps apply to most Python-based AI tools.

What you need

  • Windows 10 or 11 and a PowerShell window. Windows Terminal is fine.

  • An up-to-date graphics driver, because uv's automatic PyTorch selection looks at the driver you have installed. If you're on Linux, our Ubuntu NVIDIA driver guide covers that side.

  • Git, if you want to clone an app's source code as in the example below.

You don't need to install Python first: uv can download it for you.

Step 1: Install uv

Pick one of the methods from uv's installation page. The standalone installer runs from PowerShell:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Or use WinGet:

winget install --id=astral-sh.uv -e

uv's documentation notes that you can inspect the install script before running it with powershell -c "irm https://astral.sh/uv/install.ps1 | more". Close and reopen PowerShell afterwards so the uv command is on your PATH, then check it with uv --version.

Step 2: Install a Python version

Install the Python version your app asks for. ComfyUI's README recommends Python 3.12 to 3.14, so 3.12 is a safe choice:

uv python install 3.12

uv's documentation explains that this uses standalone Python builds from Astral's python-build-standalone project, because, in the documentation's words, "Python does not publish official distributable binaries". By default uv installs a versioned executable (such as python3.12) rather than taking over the plain python command, so it won't upset other Python installs. You can skip this step entirely: the next command downloads the version automatically if it's missing.

Step 3: Get the app and create its environment

Clone ComfyUI and create a virtual environment inside its folder:

git clone https://github.com/Comfy-Org/ComfyUI.git
cd ComfyUI
uv venv --python 3.12

This creates a .venv folder. Activate it so that python points to the environment:

.venv\Scripts\activate

If PowerShell refuses to run the activation script, Python's venv documentation notes that Windows may require you to change the execution policy for Activate.ps1. You can also skip activation for install commands: uv automatically finds and uses a .venv folder in the current directory.

Step 4: Install a GPU build of PyTorch

This is the step that catches most people out. The uv documentation explains that PyTorch's wheels on the standard Python Package Index are CPU-only for Windows, so a plain pip install torch gives you a build that can't use your graphics card. uv can choose the right build for you:

uv pip install torch torchvision torchaudio --torch-backend=auto

With --torch-backend=auto, uv checks your installed CUDA driver, AMD GPU and Intel GPU, then uses the most compatible PyTorch index. If it finds no GPU, it falls back to the CPU-only build.

You can also name a backend yourself. ComfyUI's README says CUDA 13.0 (cu130) or newer builds are required on NVIDIA 20 series cards and later, so on a GeForce RTX card you could run:

uv pip install torch torchvision torchaudio --torch-backend=cu130

AMD and Intel Arc owners should follow ComfyUI's installation document or our guides to PyTorch with ROCm on Windows and PyTorch on Intel Arc; uv's PyTorch guide lists index URLs for ROCm and Intel GPUs as well as CUDA.

Step 5: Install the app's other requirements and run it

Install the rest of ComfyUI's dependencies from its requirements file, then start it:

uv pip install -r requirements.txt
python main.py

Install PyTorch first, as above, so the requirements step finds it already installed rather than pulling the CPU-only build from PyPI. If you prefer a guided route, our standard ComfyUI on Windows guide covers the desktop and portable versions.

Step 6: Check PyTorch can see your GPU

With the environment active, run:

python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

On an NVIDIA card you should see a version ending in a CUDA tag such as +cu130, followed by True. A +cpu version means the CPU-only build was installed; repeat Step 4. Our guide to fixing "CUDA not available" in PyTorch covers other causes.

Step 7: Install AI command-line tools with uv tool

Some local AI tools are command-line programs rather than apps you run from a folder. uv tool install <package> puts each one in its own isolated environment and places its commands in a folder on your PATH; if that folder isn't on the PATH, uv shows a warning and uv tool update-shell adds it. uvx <package> runs a tool in a temporary environment without installing it, and uv tool upgrade updates installed tools. Our guide to the LLM command-line tool with Ollama is one example of a tool you can install this way.

Keeping things tidy

  • One environment per app. Repeat Steps 3 to 5 in each app's folder. If an environment breaks, delete its .venv folder and recreate it; Python's documentation says virtual environments aren't meant to be moved or copied anyway.

  • Leaving an environment. Run deactivate to exit the active environment.

  • Keep models elsewhere. Store large model files outside .venv so you can rebuild environments freely. Our guide to moving the Hugging Face cache to another drive helps if your C: drive is filling up.

  • Update uv. If you used the standalone installer, uv self update fetches the latest version. Self-update is only for the standalone installer, so if you installed uv with WinGet, update it with WinGet.

Not sure uv is the right tool for you? Our best Python environment managers for local AI guide compares it with Miniforge, Pixi and venv, and uv vs conda for local AI goes head to head.

The bottom line

Install uv with Astral's PowerShell script or winget install --id=astral-sh.uv -e, create an environment for each app with uv venv --python 3.12 and install PyTorch before anything else with uv pip install torch torchvision torchaudio --torch-backend=auto, or name a backend such as cu130. Then install the app's requirements with uv pip install -r requirements.txt and check that torch.cuda.is_available() returns True. Use uv tool install for command-line AI tools, and rebuild a broken environment by deleting its .venv folder rather than trying to repair it.

Sources

  1. 01uv documentation, Installing uv
  2. 02uv documentation, Installing Python
  3. 03uv documentation, Using Python environments
  4. 04uv documentation, Using uv with PyTorch
  5. 05uv documentation, Using tools
  6. 06Python documentation, venv - creation of virtual environments
  7. 07GitHub, Comfy-Org/ComfyUI (README)

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next