问题:如何使用Pipfile和Pipfile.lock?

在Python封装的上下文中,似乎Pipfile / Pipfile.lock旨在替代Requirements.txt。但是,关于它们如何实际工作的文献很少。我在这里的Python网站的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?


回答 0

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

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

入门

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

$ pipenv install

…,如果已经有一个requirements.txt文件,它将生成一个Pipfile带有需求的文件和一个虚拟环境文件夹,否则,它将生成一个空Pipfile文件。如果您不喜欢或改变主意,请输入…

$ pipenv uninstall <package>

…而且您很高兴。要激活已生成pipenv的虚拟环境,请继续…

$ pipenv shell

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

$ exit

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

点文件

Pipfile文件旨在指定套餐要求为您的Python应用程序或库,既要发展和执行。您只需使用…即可安装软件包。

$ pipenv install flask

…并将其添加为部署和执行的依赖项或使用…

$ pipenv install --dev pytest

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

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

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

$ pipenv lock

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

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 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.

Getting Started

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

$ pipenv install

… 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>

… 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

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

… 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

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

… 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.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。