python - 如何在 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 中包含这样的选项。
我试过的
- 使用dependency_links,但现在已弃用并忽略它。
-f
尝试安装我的库 (pip install -e . -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
)时使用命令行标志。这可行,但这不是一个解决方案,因为它每次都需要输入它,并且随着更多的 url 变得难以维护。
安装程序.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",
]
)
重现问题的步骤
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,我们就可以使用>=
它,因为它似乎是库的推荐方法。
谢谢
解决方案
推荐阅读
- html - Unicode 在 Edge 中显示奇怪
- time - 如何显示大量数据点
- php - 将合并数组添加到 PHP SQL 输出
- ios - 以编程方式增加 UIView.frame 的高度直到 iPhone 8 plus 但不适用于模型 iphone x
- r - 添加两个点和线有问题的回归图
- javascript - 带有 Javascript 的 HTML 视频
- c# - C# Winform 与 CefSharp 应用程序在发布版本上崩溃
- java - JDBC 查询不返回任何没有错误的值
- vim - 无法在鱼壳中将 Homebrew 公式编辑器设置为 vim
- python - opencv 安装后在 Python 中导入 cv2 时出错