Python Pipfile 和 Pipfile.lock 是如何使用的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46330327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:34:13  来源:igfitidea点击:

How are Pipfile and Pipfile.lock used?

pythonpip

提问by Stephen

It seems that Pipfile/Pipfile.lock are intended to be replacements for requirements.txt, in the context of Python packaging. There isn't much documentation out there on how these actually work, however. I found an evolving description of pipfile on the PyPi section of the Python website herebut it's pretty messy and doesn't explain the semantics of the different sections of the file.

在 Python 打包的上下​​文中,Pipfile/Pipfile.lock 似乎旨在替代 requirements.txt。然而,关于这些实际上如何工作的文档并不多。我发现pipfile对Python的网站的PyPI部分的演变说明在这里,但它是相当混乱和无法解释的文件不同部分的语义。

Any pointers on how to understand these files?

关于如何理解这些文件的任何指示?

回答by danieldeveloper001

The concept behind these files is simple and analogue to other already existing tools, if you have some familiarity with Ruby's Bundler or Node's Npm. Pipenvis both a package and virtual environment management tool that uses the Pipfile and Pipfile.lock files to achieve these goals.

如果您对 Ruby 的 Bundler 或 Node 的 Npm 有一定的了解,这些文件背后的概念很简单,并且类似于其他现有工具。Pipenv是一个包和虚拟环境管理工具,它使用 Pipfile 和 Pipfile.lock 文件来实现这些目标。

Pipenv handles the virtual environment for you in one default standard way (no more activate and deactivate required). Below, some basics to get you started, see more at pipenv website.

Pipenv 以一种默认的标准方式为您处理虚拟环境(不再需要激活和停用)。下面是一些帮助您入门的基础知识,请在pipenv 网站上查看更多信息

Getting Started

入门

Start using pipenv is easy, in your project folder type...

开始使用 pipenv 很容易,在您的项目文件夹类型中...

$ pipenv install

... and if it already has a requirements.txtfile, it will generate a Pipfilefile with the requirements and a virtual environment folder, otherwise, it will generate an empty Pipfilefile. If you disliked or changed your mind about something that you have installed, just type...

...如果它已经有一个requirements.txt文件,它会生成一个Pipfile包含需求和虚拟环境文件夹的文件,否则它会生成一个空Pipfile文件。如果您不喜欢或改变了对已安装的某些内容的看法,只需键入...

$ pipenv uninstall <package>

... and you're good to go. To activate the virtual environment that pipenv already generated, go with...

......你可以走了。要激活 pipenv 已经生成的虚拟环境,请使用...

$ pipenv shell

... and your virtual environment will be activated. To leave the environment...

...您的虚拟环境将被激活。离开环境...

$ exit

... and you will be back to your original terminal session.

...您将回到原来的终端会话。

Pipfile

文件

The Pipfilefile is intended to specify packages requirements for your Python application or library, both to development and execution. You can install a package by simply using...

Pipfile文件旨在指定套餐要求为您的Python应用程序或库,既要发展和执行。您可以通过简单地使用...

$ pipenv install flask

... and it will be added as a dependency for deployment and execution or by using ...

... 它将作为部署和执行的依赖项添加或通过使用 ...

$ pipenv install --dev pytest

... and it will be used as a depencency for development time. The file syntax is pretty straight forward, as follows.

...它将被用作开发时间的依赖。文件语法非常简单,如下所示。

[[source]] # Here goes your package sources (where you are downloading your packages from).
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages] # Here goes your package requirements for running the application and its versions (which packages you will use when running the application).
requests = "*"
flask = "*"
pandas = "*"

[dev-packages] # Here goes your package requirements for developing the application and its versions (which packaes you will use when developing the application)
pylint = "*"
wheel = "*"

[requires] # Here goes your required Python version.
python_version = "3.6"

Pipfile.lock

pipfile.lock

The Pipfile.lockis intended to specify, based on the packages present in Pipfile, which specific version of those should be used, avoiding the risks of automatically upgrading packages that depend upon each other and breaking your project dependency tree.

Pipfile.lock是用来规定的基础上,目前在包装Pipfile,应使用哪个那些特定版本,避免自动升级依赖于对方的包和破坏你的项目的依赖关系树的风险。

You can lock your currently installed packages using...

您可以使用...锁定当前安装的软件包

$ pipenv lock

... and the tool will lookup your virtual environment folder to generate the lock file for you automatically, based on the currently installed versions. The file syntax is not as obvious as is for Pipfile, so for the sake of conciseness, it will not be displayed here.

...并且该工具将根据当前安装的版本查找您的虚拟环境文件夹以自动为您生成锁定文件。文件语法不像Pipfile那样明显,为简洁起见,这里不再显示。