首页 > 解决方案 > 如何在 setup.py 中添加 PyTorch LTS 版本?

问题描述

我想知道如何在我的 setup.py 文件中包含 pytorch LTS版本的库。

https://pytorch.org/get-started/locally/#start-locally上的说明,我们可以看到它需要额外的信息才能找到包。这是他们建议的命令:
pip3 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio==0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html

注意最后的标志-f https://download.pytorch.org/whl/lts/1.8/torch_lts.html

我想知道,如何在 setup.py 中包含这样的选项。

我试过的

安装程序.py

这是我的 setup.py 现在的样子。

from setuptools import setup

setup(
    name="my_library",
    version="0.1",
    description="my library description",
    packages=["my_library"],
    python_requires=">=3.8",
    install_requires=[
        "torch==1.8.2+cu111@https://download.pytorch.org/whl/lts/1.8/torch_lts.html",
        "torchvision==0.9.2+cu111@https://download.pytorch.org/whl/lts/1.8/torch_lts.html",
        "pillow>=8.0.0",
        "numpy>=1.21.0",
        "timm==0.4.12",
    ]
)

重现问题的步骤

  1. pip install -e . --no-cache-dir

实际输出

ERROR: Could not find a version that satisfies the requirement torch==1.8.2+cu111@https://download.pytorch.org/whl/lts/1.8/torch_lts.html (from mdai-core==0.1) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0)
ERROR: No matching distribution found for torch==1.8.2+cu111@https://download.pytorch.org/whl/lts/1.8/torch_lts.html

预期产出

没有错误,pytorch lts 的安装过程应该开始。

PS:==版本要求中的要求是出于测试目的,因此它不会下载 1.9 非 LTS。一旦我们确定它使用 LTS,我们就可以使用>=它,因为它似乎是库的推荐方法。

谢谢

标签: pythonpippytorchdependenciessetup.py

解决方案


推荐阅读