(我认为[!])我了解pipenv(以及其他venvs)背后的原理并经常使用它们。但是,我从来没有真正理解为什么 pipenv 需要一个 Pipfile 和一个 Pipfile.lock 文件。
Now, once you get your code and Pipfile.lock in your production environment, you should install the last successful environment recorded:
$ pipenv install --ignore-pipfile
但它没有解释为什么 Pipfile.lock 需要被使用。即 .lock 文件包含哪些 Pipfile 不包含的内容,以及为什么 Pipfile 足以与其他开发人员共享:
Now let’s say another developer wants to make some additions to your code. In this situation, they would get the code, including the Pipfile, and use this command:
$ pipenv install --dev
但还不足以用于在生产环境中复制您的环境吗?
请您参考如下方法:
官方 Pipfile 项目 has something to say about this :
The concrete requirements for a Python Application would come from
Pipfile. This would include where the packages should be fetched from and their loose version constraints.The details of the environment (all installed packages with pinned versions and other details) would be stored in
Pipfile.lock, for reproducibility. This file will be automatically generated and should not be modified by the user.
换句话说,Pipfile 用于人,Pipfile.lock 用于计算机。
在您的 Pipfile 中,您列出了您想要的内容,并以一种有点松散的方式定义它们,例如“Django 版本 2 或更高版本”。但这还不足以确定性地重现环境。这意味着“Django 2.0.3”还是“Django 2.1.0”?
Pipfile.lock 准确地指定了要求,它还准确地指定了依赖性。例如,如果您明确想要 foo 并将其放入您的 Pipfile,您的 Pipfile.lock 将生成,将其锁定到特定版本.如果foo本身依赖于bar,而bar依赖于quux和florp, Pipfile.lock 文件也会锁定 bar、quux 和 florp,因此依赖项中的细微差别不会'打破东西。
