【问题标题】:How to convert pip install to Poetry file?如何将 pip install 转换为诗歌文件?
【发布时间】:2021-02-28 10:55:21
【问题描述】:

经过数小时的研究,我仍然想不出将这个 pip install cmd 转换为 pyproject.toml 的方法 文件。我正在尝试安装 PyTorch。

pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

这是我目前得到的(完全错误!)

[tool.poetry]
name = "poetry-test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.8"
torch = "^1.7.0"
torchvision = "^0.8.1"
torchaudio = "^0.7.0"

[tool.poetry.dependencies.torch]
url = "https://download.pytorch.org/whl/torch_stable.html"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

【问题讨论】:

  • 原来有一种方法可以安装torch。你在窗户上,对吧?

标签: python pip pytorch torchvision python-poetry


【解决方案1】:

正如这首诗issue#2543 中提到的那样,以前的解决方案对我不起作用。所以在此期间对我有用的是升级到解决该问题的版本 1.2(预览版)。

安装诗歌 1.2

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - --preview

按照此处issue#4124 的建议将以下 repo 添加到您的 pyproject.toml,并且您不应该得到版本不匹配。

[[tool.poetry.source]]
name = "torch_rep"
url = "https://eternalphane.github.io/pytorch-pypi"

之后,您可以继续安装它们 poetry add torch =1.7.0+cpu poetry add torchvision=0.8.1+cpu

或者,将依赖项添加到 pyproject.toml 并执行 poetry install 也应该有效。

【讨论】:

    【解决方案2】:

    如果您在依赖项定义中使用 url 说明符,它需要直接指向您要安装的文件,而不是 .html 页面:

    [tool.poetry.dependencies]
    python = "^3.8"
    torch = {url = "https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp38-cp38-win_amd64.whl"}
    torchaudio = {url = "https://download.pytorch.org/whl/torchaudio-0.7.0-cp38-none-win_amd64.whl"}
    torchvision = {url = "https://download.pytorch.org/whl/cpu/torchvision-0.8.1%2Bcpu-cp38-cp38-win_amd64.whl"}
    

    话虽如此,您的设置现在无法使用poetry 安装,因为您将遇到求解器错误:

    [SolverProblemError]
    Because torchaudio (0.7.0) depends on torch (1.7.0) which doesn't match any versions, torchaudio is forbidden.
    So, because no versions of torchaudio match !=0.7.0
     and poetry-test depends on torchaudio (*), version solving failed.
    

    虽然torch 可以单独安装,但在安装torchaudiotorchvision 时匹配版本会出现问题。也许这与torch在您尝试安装的轮子中的版本中包含构建信息有关(即1.7.0+cpu),也许是因为无法在@987654331中为url表示的依赖项分配版本@ (这是有道理的,如果我们告诉它“这是一个 tarball,安装它!”,它不会像诗歌一样解决任何问题),或者可能只是一个内部 poetry 错误。

    你现在可能不得不坚持使用pip,因为它不会抱怨解决依赖关系树,而是开始安装。但归根结底,归咎于 torch 维护者,因为 1) 没有将所有轮子上传到 global Python package index,以及 2) 甚至没有以 PEP-503 一致的方式设置自己的文件服务器。


    更新:

    我对讨论进行了更多研究,似乎a helpful someone 已经完成了torch 在符合 PEP-503 的服务器上提供轮子的工作。因此,目前,以下内容实际上会起作用:

    [tool.poetry]
    name = "poetry-test"
    version = "0.1.0"
    description = ""
    authors = ["Your Name <you@example.com>"]
    
    [[tool.poetry.source]]
    name = "foo"
    url = "https://vxlabs.com/pypi//simple/"
    
    [tool.poetry.dependencies]
    python = "^3.8"
    torch = "1.7.0"
    torchvision = "0.8.1"
    torchaudio = "0.7.0"
    
    [build-system]
    requires = ["poetry>=0.12"]
    build-backend = "poetry.masonry.api"
    

    【讨论】:

      猜你喜欢
      • 2021-02-24
      • 2022-07-16
      • 2021-07-14
      • 1970-01-01
      • 2022-11-04
      • 2022-12-17
      • 2022-01-25
      • 2022-08-16
      • 2022-10-21
      相关资源
      最近更新 更多