首页 > 解决方案 > 如何从 requirements.txt 文件中选择特定版本

问题描述

我有 requirements.txt 文件,我在其中给出了带有版本的自定义包名称,如下所示,

custom-package >= 1.0.1

现在在我的仓库中,我有如下版本

custom-package-1.0.1.tar.gz
custom-package-1.0.4.tar.gz
custom-package-5.0.0.tar.gz

现在如果我运行 pip install requirements.txt ,那么它会选择 5.0.0。这是可以理解的。但我怎么能确定,它应该只选择以 1 而不是 5 开头的版本。

标签: python

解决方案


如果您想要任何以 1 开头的版本,只需指定版本不应超过 2.0.0:

custom-package >= 1.0.1, < 2.0.0

或者如果你想要一个确切的版本:

custom-package == 1.0.1

推荐阅读