python - 当包源来自特定网站时,如何格式化 requirements.txt?
问题描述
我正在尝试使用从另一个网站下载的 pip 将以下安装命令转换为 requirements.txt 格式,但无法弄清楚如何。有人可以帮忙吗?
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
解决方案
[[--option]...] <requirement specifier> [; markers] [[--option]...] <archive url/path> [-e] <local project path> [-e] <vcs project url>
定义包<requirement specifier>
和可选版本。
SomeProject SomeProject == 1.3 SomeProject >=1.2,<2.0 SomeProject[foo, bar] SomeProject~=1.4.2
(--option
例如-f
/--find-links
)与从命令行执行时将使用的pip 安装选项相同。pip install
支持以下选项:
- -i, --index-url
- --extra-index-url
- --无索引
- -c,--约束
- -r,--要求
- -e,--可编辑
- -f,--查找链接
- --无二进制
- --仅二进制
- --需要哈希
- --pre
- --可信主机
因此,对于您的安装命令,requirements.txt 将如下所示:
# Torch
--find-links https://download.pytorch.org/whl/torch_stable.html
torch==1.5.0+cu101
torchvision==0.6.0+cu101
# Detectron
--find-links https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
detectron2
确保验证链接是否正确使用:
$ pip install -r requirements.txt
Looking in links: https://download.pytorch.org/whl/torch_stable.html, https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
Collecting torch==1.5.0+cu101 (from -r requirements.txt (line 3))
Using cached https://download.pytorch.org/whl/cu101/torch-1.5.0%2Bcu101-cp38-cp38-linux_x86_64.whl
Collecting torchvision==0.6.0+cu101 (from -r requirements.txt (line 4))
Using cached https://download.pytorch.org/whl/cu101/torchvision-0.6.0%2Bcu101-cp38-cp38-linux_x86_64.whl
Collecting detectron2 (from -r requirements.txt (line 8))
Using cached https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/detectron2-0.1.2%2Bcu101-cp38-cp38-linux_x86_64.whl
...
作为旁注,您最初在标题中说“(不是 github)”。使用安装的包的默认源pip
托管在 PyPi 上:https ://files.pythonhosted.org/ 。转到 PyPi 中软件包的下载文件部分时,您可以看到实际链接(以Torch为例)。
推荐阅读
- android - 有没有办法确定用户在预注册期间是否在 Google Play 上安装了应用程序?
- css - Tailwind Grid Height and Width - Navbar Height
- angular - 如何使用 Angular http 客户端复制表单操作帖子
- docker - 如果未在主机上定义上下文,则 docker 容器中的 chcon 返回 EINVAL
- xslt - XSLT - 删除比较日期的 XML 节点
- redis - Redis 数据从旧版本转储到新 Redis 版本
- c# - MQTT 客户端 ASP.NET Core 的使用
- node.js - 如何映射从 mongoDB 获取的字符串数组并在每个帖子中显示一个特定的标题/正文
- javascript - 使用带有 JSON 数据的 Input 组件创建 Cascading 3 Level Select Dropdown
- azure - 为什么 Azure DevOps 不选择具有整数参数的 ARM 部署?