[Python] PyTorch installed via uv project shows CPU-only version on Windows with CUDA...

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to set up a Python project using uv and pyproject.toml on Windows. I want to install the CUDA-enabled PyTorch, but after installing, when I check the version, it shows CPU-only.

    Here’s my pyproject.toml setup:

    [project]
    name = "transformerpractice"
    version = "0.1.0"
    description = "Add your description here"
    readme = "README.md"
    requires-python = ">=3.10"
    dependencies = [
    "en-core-web-sm",
    "ko-core-news-sm",
    "openpyxl>=3.1.5",
    "pandas>=2.3.3",
    "spacy>=3.8.8",
    "torchtext==0.16.0",
    "torch==2.1.0",
    ]

    [tool.uv.sources]
    en-core-web-sm = { url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0.tar.gz" }
    ko-core-news-sm = { path = "tokenizer/ko_core_news_sm-3.8.0-py3-none-any.whl" }
    torch = [
    { index = "pytorch-cu121", marker = "sys_platform == 'win_amd64'" },
    ]

    [[tool.uv.index]]
    name = "pytorch-cu121"
    url = "https://download.pytorch.org/whl/cu121"
    explicit = false


    After installing, I run:

    import torch

    print(torch.__version__)
    print(torch.version.cuda)


    And the output is:

    2.1.0+cpu
    None


    It seems like the CPU version is installed, not the CUDA version.

    What I tried:


    1. Specifying the PyTorch version with torch==2.1.0 in [project.dependencies].


    2. Adding a custom PyTorch index with CUDA support using [tool.uv.index].


    3. Checking that I'm on Windows 64-bit (sys_platform == 'win_amd64').

    Question:

    How can I configure pyproject.toml with uv so that it installs the CUDA-enabled PyTorch (2.1.0+cu121) on Windows?

    Any guidance on how uv handles extra indices and platform markers for PyTorch would be helpful.

    Continue reading...

Compartilhe esta Página