Python 点子冻结与点子列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18966564/
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 12:27:18  来源:igfitidea点击:

Pip freeze vs. pip list

pythonpython-2.7python-3.xpip

提问by nitrl

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

Pip 的文档说明

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

but what is "requirements format," and why does pip listgenerate a more comprehensive list than pip freeze?

但是什么是“需求格式”,为什么会pip list生成比 更全面的列表pip freeze

采纳答案by karthikr

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

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

A typical usage:

典型用法:

$ pip install -r requirements.txt

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

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

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

That is the "requirements format".

那就是“需求格式”。

Here, django==1.4.2implies install djangoversion 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.

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

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

您可以在“ Virtualenv 和 pip 基础知识”和官方“需求文件格式”文档中阅读更多内容。

回答by ForeverWintr

To answer the second part of this question, the two packages shown in pip listbut not pip freezeare setuptools(which is easy_install) and pipitself.

要回答这个问题的第二部分,显示pip list但未显示的两个包pip freezesetuptools(easy_install)和pip它本身。

It looks like pip freezejust doesn't list packages that pip itself depends on. You may use the --allflag to show also those packages.

看起来pip freeze只是没有列出 pip 本身所依赖的包。您也可以使用该--all标志来显示这些包。

From the documentation:

文档

--all

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

--all

不要在输出中跳过这些包:pip、setuptools、distribute、wheel

回答by Serjik

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

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

pip list

点子列表

List installed packages, including editables.

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

pip freeze

点冻结

Output installed packages in requirements format.

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

So there are two differences:

所以有两个区别:

  1. Output format, freezegives us the standard requirement format that may be used later with pip install -rto install requirements from.

  2. Output content, pip listinclude editables which pip freezedoes not.

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

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

回答by Daniel Lahyani

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

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

In other words you can run: pip freeze > frozen-requirements.txton one machine and then later on a different machine or on a clean environment you can do: pip install -r frozen-requirements.txtand 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.

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

回答by F1Linux

pip listshows ALLpackages.

pip list显示所有包。

pip freezeshows packages YOUinstalled via pip(or pipenvif using that tool) command in a requirements format.

pip freeze以需求格式显示通过pip(或pipenv如果使用该工具)命令安装的软件包。

Remark below that setuptools, pip, wheelare installed when pipenv shellcreates my virtual envelope. These packages were NOTinstalled by me using pip:

请注意下面创建我的虚拟信封时安装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>

Now review & compare the output of the respective commands where I've only installed cool-liband sampleproject(of which peppercornis a dependency):

现在查看并比较我只安装了cool-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