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
Pip freeze vs. pip list
提问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 list
generate a more comprehensive list than pip freeze
?
但是什么是“需求格式”,为什么会pip list
生成比 更全面的列表pip freeze
?
采纳答案by karthikr
When you are using a virtualenv
, you can specify a requirements.txt
file 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 pip
to 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.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.
在这里,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 list
but not pip freeze
are setuptools
(which is easy_install) and pip
itself.
要回答这个问题的第二部分,显示pip list
但未显示的两个包pip freeze
是setuptools
(easy_install)和pip
它本身。
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.
看起来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:
所以有两个区别:
Output format,
freeze
gives us the standard requirement format that may be used later withpip install -r
to install requirements from.Output content,
pip list
include editables whichpip freeze
does not.
输出格式,
freeze
为我们提供了标准的需求格式,稍后可用于pip install -r
安装需求。输出内容,
pip list
包括pip freeze
不包含的可编辑内容。
回答by Daniel Lahyani
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.
主要区别在于可以将 的输出pip freeze
转储到一个 requirements.txt 文件中,以便稍后用于重新构建“冻结”环境。
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.
换句话说,您可以运行:pip freeze > frozen-requirements.txt
在一台机器上运行,然后在另一台机器上运行
,或者在一个干净的环境中运行:
pip install -r frozen-requirements.txt
您将获得一个完全相同的环境,安装的依赖项与您在原始环境中安装的依赖项完全相同生成了frozen-requirements.txt。
回答by F1Linux
pip list
shows ALLpackages.
pip list
显示所有包。
pip freeze
shows packages YOUinstalled via pip
(or pipenv
if using that tool) command in a requirements format.
pip freeze
以需求格式显示您通过pip
(或pipenv
如果使用该工具)命令安装的软件包。
Remark below that setuptools, pip, wheelare installed when pipenv shell
creates my virtual envelope. These packages were NOTinstalled by me using pip
:
请注意下面创建我的虚拟信封时安装setuptools、pip、wheelpipenv 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-lib和sampleproject(其中胡椒是一个依赖项)的各个命令的输出:
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