点冻结与点列表

问题:点冻结与点列表

比较输出结果可发现差异:

user@user-VirtualBox:~$ pip list
feedparser (5.1.3)
pip (1.4.1)
setuptools (1.1.5)
wsgiref (0.1.2)
user@user-VirtualBox:~$ pip freeze
feedparser==5.1.3
wsgiref==0.1.2

Pip的文档状态

freeze                      Output installed packages in requirements format.
list                        List installed packages.

但是什么是“需求格式”?为什么pip list生成的清单比清单更全面pip freeze

A comparison of outputs reveals differences:

user@user-VirtualBox:~$ pip list
feedparser (5.1.3)
pip (1.4.1)
setuptools (1.1.5)
wsgiref (0.1.2)
user@user-VirtualBox:~$ pip freeze
feedparser==5.1.3
wsgiref==0.1.2

Pip’s documentation states

freeze                      Output installed packages in requirements format.
list                        List installed packages.

but what is “requirements format,” and why does pip list generate a more comprehensive list than pip freeze?


回答 0

使用时virtualenv,可以指定一个requirements.txt文件来安装所有依赖项。

典型用法:

$ pip install -r requirements.txt

软件包需要采用特定的格式pip才能理解,即

feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...

那就是“要求格式”。

在这里,django==1.4.2意味着安装django版本1.4.2(即使最新版本是1.6.x)。如果您未指定==1.4.2,则会安装可用的最新版本。

您可以在“ Virtualenv和pip基础知识 ”以及官方的“ Requirements File Format ”文档中阅读更多内容。

When you are using a virtualenv, you can specify a requirements.txt file to install all the dependencies.

A typical usage:

$ pip install -r requirements.txt

The packages need to be in a specific format for pip to understand, which is

feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...

That is the “requirements format”.

Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x). If you do not specify ==1.4.2, the latest version available would be installed.

You can read more in “Virtualenv and pip Basics“, and the official “Requirements File Format” documentation.


回答 1

为了回答这个问题的第二部分,显示pip list但没有显示的两个软件包pip freezesetuptools(easy_install)和它们pip本身。

它看起来像pip freeze少了点列表软件包点子本身依赖。您可以使用该--all标志来显示那些软件包。

文档中

--all

不要在输出中跳过以下软件包:pip,setuptools,distribute,wheel

To answer the second part of this question, the two packages shown in pip list but not pip freeze are setuptools (which is easy_install) and pip itself.

It looks like pip freeze just doesn’t list packages that pip itself depends on. You may use the --all flag to show also those packages.

From the documentation:

--all

Do not skip these packages in the output: pip, setuptools, distribute, wheel


回答 2

主要区别在于可以将的输出pip freeze转储到requirements.txt文件中,并在以后用于重建“冻结”环境。

换句话说,您可以运行:pip freeze > frozen-requirements.txt在一台计算机上运行 ,然后再在另一台计算机上或干净的环境中运行: pip install -r frozen-requirements.txt 您将获得与安装原始环境时所安装的依赖项完全相同的相同环境生成了Frozen-requirements.txt。

The main difference is that the output of pip freeze can be dumped into a requirements.txt file and used later to re-construct the “frozen” environment.

In other words you can run: pip freeze > frozen-requirements.txt on one machine and then later on a different machine or on a clean environment you can do: pip install -r frozen-requirements.txt and you’ll get the an identical environment with the exact same dependencies installed as you had in the original environment where you generated the frozen-requirements.txt.


回答 3

查看pip文档,该文档将两者的功能描述为:

点列表

列出已安装的软件包,包括可编辑的软件包。

点冻结

以需求格式输出已安装的软件包。

因此有两个区别:

  1. 输出格式,freeze为我们提供了标准的需求格式,以后可以用来pip install -r安装需求。

  2. 输出内容,pip list包括pip freeze不包含的可编辑内容。

Look at the pip documentation, which describes the functionality of both as:

pip list

List installed packages, including editables.

pip freeze

Output installed packages in requirements format.

So there are two differences:

  1. Output format, freeze gives us the standard requirement format that may be used later with pip install -r to install requirements from.

  2. Output content, pip list include editables which pip freeze does not.


回答 4

pip list显示所有软件包。

pip freeze示出了包YOU经由安装pip(或pipenv如果使用该工具)在要求的格式命令。

在下面说明创建虚拟信封时已安装setuptoolspipwheelpipenv shell。这些软件包不是我使用pip以下软件安装的:

test1 % pipenv shell
Creating a virtualenv for this project
Pipfile: /Users/terrence/Development/Python/Projects/test1/Pipfile
Using /usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/python3.8 (3.8.1) to create virtualenv
 Creating virtual environment...
<SNIP>
Installing setuptools, pip, wheel...
done.
 Successfully created virtual environment! 
<SNIP>

现在回顾与比较,我已经只安装了相应的命令的输出冷LIBsampleproject(其中胡椒是一个依赖):

test1 % pip freeze       <== Packages I'VE installed w/ pip

-e git+https://github.com/gdamjan/hello-world-python-package.git@10<snip>71#egg=cool_lib
peppercorn==0.6
sampleproject==1.3.1


test1 % pip list         <== All packages, incl. ones I've NOT installed w/ pip

Package       Version Location                                                                    
------------- ------- --------------------------------------------------------------------------
cool-lib      0.1  /Users/terrence/.local/share/virtualenvs/test1-y2Zgz1D2/src/cool-lib           <== Installed w/ `pip` command
peppercorn    0.6       <== Dependency of "sampleproject"
pip           20.0.2  
sampleproject 1.3.1     <== Installed w/ `pip` command
setuptools    45.1.0  
wheel         0.34.2

pip list shows ALL installed packages.

pip freeze shows packages YOU installed via pip (or pipenv if using that tool) command in a requirements format.

Remark below that setuptools, pip, wheel are installed when pipenv shell creates my virtual envelope. These packages were NOT installed by me using pip:

test1 % pipenv shell
Creating a virtualenv for this project…
Pipfile: /Users/terrence/Development/Python/Projects/test1/Pipfile
Using /usr/local/Cellar/pipenv/2018.11.26_3/libexec/bin/python3.8 (3.8.1) to create virtualenv…
⠹ Creating virtual environment...
<SNIP>
Installing setuptools, pip, wheel...
done.
✔ Successfully created virtual environment! 
<SNIP>

Now review & compare the output of the respective commands where I’ve only installed cool-lib and sampleproject (of which peppercorn is a dependency):

test1 % pip freeze       <== Packages I'VE installed w/ pip

-e git+https://github.com/gdamjan/hello-world-python-package.git@10<snip>71#egg=cool_lib
peppercorn==0.6
sampleproject==1.3.1


test1 % pip list         <== All packages, incl. ones I've NOT installed w/ pip

Package       Version Location                                                                    
------------- ------- --------------------------------------------------------------------------
cool-lib      0.1  /Users/terrence/.local/share/virtualenvs/test1-y2Zgz1D2/src/cool-lib           <== Installed w/ `pip` command
peppercorn    0.6       <== Dependency of "sampleproject"
pip           20.0.2  
sampleproject 1.3.1     <== Installed w/ `pip` command
setuptools    45.1.0  
wheel         0.34.2