Pipfile 和 Pipfile.lock 是如何使用的? [英] How are Pipfile and Pipfile.lock used?

查看:59
本文介绍了Pipfile 和 Pipfile.lock 是如何使用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 打包的上下​​文中,Pipfile/Pipfile.lock 似乎旨在替代 requirements.txt.然而,关于这些实际上如何工作的文档并不多.我在 Python 网站 here 的 PyPi 部分找到了对 pipfile 的不断发展的描述很乱,没有解释文件不同部分的语义.

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 here but it's pretty messy and doesn't explain the semantics of the different sections of the file.

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

Any pointers on how to understand these files?

推荐答案

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

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. Pipenv is both a package and virtual environment management tool that uses the Pipfile and Pipfile.lock files to achieve these goals.

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

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 很容易,在您的项目文件夹类型中...

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

$ pipenv install

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

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

$ pipenv uninstall <package>

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

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

$ 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 文件旨在指定 Python 应用程序或库的包要求,包括开发和执行.您可以通过简单地使用...安装软件包

The Pipfile file 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...

$ pipenv install flask

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

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

$ pipenv install --dev pytest

... 它将用作开发时间的依赖项.在这两种情况下,如果您需要更具体地了解包版本,如 文档 pipenv 使用相同的 pip 使用的版本说明符.文件语法非常简单,如下所示.

... and it will be used as a dependency for development time. In both cases, if you need to be more specific about the package version, as stated in the documentation pipenv makes use of the same version specifiers used by pip. 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 packages you will use when developing the application)
pylint = "*"
wheel = "*"

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

Pipfile.lock

Pipfile.lock 旨在根据 Pipfile 中存在的包指定应该使用哪个特定版本,避免自动升级包的风险相互依赖并破坏您的项目依赖树.

Pipfile.lock

The Pipfile.lock is 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.

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

You can lock your currently installed packages using...

$ pipenv lock

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

... 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 和 Pipfile.lock 是如何使用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆