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

查看:651
本文介绍了如何使用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?

推荐答案

如果您对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

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

... 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 用于根据 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天全站免登陆