首页 > 解决方案 > 无法通过 windows 中的诗歌安装 torchvision

问题描述

感谢Poetry 和 PyTorch的回答,我成功安装了 pytorch 。

但是,我仍然无法通过诗歌安装 torchvision。

> poetry add torchvision==0.8.2

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing torchvision (0.8.2)

  RuntimeError

  Unable to find installation candidates for torchvision (0.8.2)

  at ~\.poetry\lib\poetry\installation\chooser.py:72 in choose_for
       68│ 
       69│             links.append(link)
       70│
       71│         if not links:
    →  72│             raise RuntimeError(
       73│                 "Unable to find installation candidates for {}".format(package)
       74│             )
       75│
       76│         # Get the best link


Failed to add packages, reverting the pyproject.toml file to its original content.

我用谷歌搜索了一些答案,上面写着“只是pip install torchvision”。但我怀疑它是否有效,因为根据 PyPi(https://pypi.org/project/torchvision/#files),Windows 没有轮文件。我尝试了它,但它失败了,正如我所料。

有什么方法可以在 Windows 中安装与最新的 torch(1.7.1) 兼容的最新的 torchvisin?+ 通过诗歌?

标签: pythonpytorchpython-poetry

解决方案


  1. https://download.pytorch.org/whl/torch_stable.html中查找您要安装的版本(torchvision 版本、python 版本、CUDA 版本、操作系统等)
  2. 将 URL 依赖项添加到您的pyproject.toml文件中。例如,我的依赖项中有 torchvision 1.8.0 使用以下内容
[tool.poetry.dependencies]
python = "^3.8"
torch = {url = "https://download.pytorch.org/whl/cu102/torch-1.8.0-cp38-cp38-win_amd64.whl"}
torchvision = {url = "https://download.pytorch.org/whl/cu102/torchvision-0.9.0-cp38-cp38-win_amd64.whl"}
  1. 从您激活的虚拟环境中poetry update torchvision,您应该一切顺利。

推荐阅读