【问题标题】:How to make pip run a specific command from requirements file?如何让 pip 从需求文件中运行特定命令?
【发布时间】:2020-08-18 06:39:16
【问题描述】:

我想在我的 requirements.txt 文件中添加 torchtorchvision 行,以便轻松克隆,我将在不久的将来从计算机迁移到计算机并迁移到云。

我想要一个简单的 pip install -r requirements.txt 并为我的项目完成它。

> pip freeze > requirements.txt

给出类似的东西

...
torch==1.5.0
torchvision==0.6.0
...

但是,pip install -r requirements.txt(实际上是pip install torch)不起作用,相反,正如official torch site,明确表示该命令应该是:

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html

如何让需求文件反映这一点?

我的桌面是 Windows 10。


额外问题:

我的云是基于 Linux 的。
如何使需求文件适合桌面和云?

【问题讨论】:

  • 你能澄清一下你所说的“不起作用”是什么意思吗?您收到的错误信息是什么?
  • @DavidZ 找不到满足要求的版本 torch===1.5.0(来自 -r requirements.txt(第 19 行))(来自版本:0.1.2、0.1.2。 post1, 0.1.2.post2) 没有为 torch===1.5.0 找到匹配的分布(来自 -r requirements.txt(第 19 行))
  • 哦,我的意思是把它编辑成问题。 cmets 中的信息可能会在一段时间后丢失。

标签: python pip pytorch virtualenv requirements.txt


【解决方案1】:

You can use the same options in your requirements.txt file例如

torch===1.5.0
torchvision===0.6.0
-f https://download.pytorch.org/whl/torch_stable.html

然后只需运行pip install -r requirements.txt

【讨论】:

  • 不错。如果版本对操作系统敏感,或者更好,对操作系统不敏感呢?
  • 每行基础上也是可行的
  • @michaeldel 好的,你能解释一下为什么官方网站上的命令不同吗?只是为了 Linux 用户的美丽?
  • 指定的包可能需要外部库(作为二进制文件或作为编译源),这些库可能无法使用pip 在 Windows 上正确安装,因此 -f 要求链接到已编译的轮文件。有关更多信息,请参阅此答案stackoverflow.com/a/29503549/1812262
  • @sinoroc 实际上不能内联工作,并出现与我在问题中发布的相同的错误。
猜你喜欢
  • 2015-07-01
  • 1970-01-01
  • 2017-08-25
  • 2015-08-13
  • 2020-12-10
  • 2021-11-19
  • 1970-01-01
  • 2011-05-30
  • 2016-02-05
相关资源
最近更新 更多