为什么不应该将版本号固定在 Pipfile 中?

Why should version numbers not be pinned in a Pipfile?

我正在研究使用 pipenv 和此处的文档
https://pipenv.pypa.io/en/latest/basics/#importing-from-requirements-txt

它说(强调我的)

Note, that when importing a requirements file, they often have version numbers pinned, which you likely won’t want

这是为什么?

我知道 Pipfile.lock 文件将存储我安装的依赖项的特定版本和哈希值,但我不想看到 Pipfile 中安装的特定版本吗? (和我使用 requirements.txt 时一样吗?)

don't I want to be able to see the specific versions of what is installed in the Pipfile?

锁定文件用于跟踪实际安装的内容,是生成确定性构建的关键。 Pipfile.lock 旨在与 Pipfile 一起提交给一个项目。还有一种观点认为,理想的工作流程是使用“pipenv lock 来编译您对开发环境的依赖项,并将编译后的 Pipfile.lock 部署到您所有的生产环境以实现可重现的构建."

您需要在 Pipfile 中指定一些版本。例如,低于某个主要版本的所有 Django 版本可能是个好主意。

还了解到,截至目前,pipenv 仍在积极开发中,因此其中一些想法仍在制定中。可能会有一些变化。

我不确定以前是什么情况,但是,the latest documentation 说您可以在安装时指定软件包的版本号,如下所示:

pipenv install requests==2.13.0

这也会更新您 Pipfile 中的包以包含版本号,如下所示:

requests = "==2.13.0"

您可以为每个要为其指定版本号的软件包执行此操作——包括如果您之前安装过它们。

我认为您可以手动编辑 Pipfile 来执行此操作,但我不确定这是否正确。

文档对您将版本固定在需求文件中的可能原因颇有意见:它可能来自 pip freeze > requirements.txt

当然你会想在你的 Pipfile 中指定一些或所有版本范围,只是很多人把它们固定在 requirements.txt 中,因为他们过去把它当作一种Pipfile.lock,指定甚至不是直接依赖项的软件包版本。当然,如果你没有遵循这种做法,你不必担心那个警告。

这很可能是 Kenneth Reitz(Pipenv 创建者)自己之前这样做的结果,正如他的博客 post A Better Pip Workflow. Clarification on this matter was already asked and answered by him in the official repository.

2018 年 6 月更新

该消息过去也被 pipenv 命令打印为警告,但已被替换为

requirements.txt found, instead of Pipfile! Converting…
Warning: Your Pipfile now contains pinned versions, if your requirements.txt did.
We recommend updating your Pipfile to specify the "*" version, instead.

更友好一点,但我认为它仍然含蓄地说在 Pipfile 上固定版本并不理想,这是不正确的。完全没问题。