nit*_*trl 92 python pip python-2.7 python-3.x
产出比较揭示了差异:
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
Run Code Online (Sandbox Code Playgroud)
Pip的文档说明
freeze Output installed packages in requirements format.
list List installed packages.
Run Code Online (Sandbox Code Playgroud)
但是什么是"需求格式",为什么pip list生成比这更全面的列表pip freeze呢?
kar*_*ikr 96
使用a时virtualenv,可以指定一个requirements.txt文件来安装所有依赖项.
典型用法:
$ pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
包需要采用特定的格式pip才能理解,即
feedparser==5.1.3
wsgiref==0.1.2
django==1.4.2
...
Run Code Online (Sandbox Code Playgroud)
这就是"要求格式".
这里,django==1.4.2暗示安装django版本1.4.2(即使最新的是1.6.x).如果未指定==1.4.2,则将安装可用的最新版本.
您可以在" Virtualenv和pip Basics "以及官方的" 需求文件格式 "文档中阅读更多内容.
For*_*ntr 35
要回答这个问题的第二部分,所示的两个包pip list,但不能pip freeze是setuptools(这是easy_install的)和pip本身.
它似乎pip freeze只是没有列出pip本身依赖的包.您可以使用该--all标志来显示这些包.
从文档:
--all不要在输出中跳过这些包:pip,setuptools,distribute,wheel
Dan*_*ani 29
主要区别在于输出pip freeze可以转储到requirements.txt文件中,以后用于重新构建"冻结"环境.
换句话说,您可以pip freeze > frozen-requirements.txt在一台计算机上运行:
稍后在另一台计算机上运行,或者在干净的环境中运行:
pip install -r frozen-requirements.txt
您将获得一个相同的环境,其安装的完全相同,就像您在原始环境中一样生成了frozen-requirements.txt.
col*_*ham 21
我生成需求文件的首选方法是:
pip list --format=freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)
此方法仅保留包名称和包版本,而不会链接到本地文件路径,而“pip freeze”有时会单独提供给我。需求文件中的本地文件路径使您的代码库更难被其他用户使用,并且一些开发人员不知道如何解决此问题,因此我更喜欢这种方法,以便于采用。
pip list显示所有已安装的软件包。
pip freeze以需求格式显示您通过pip(或pipenv如果使用该工具)命令安装的软件包。
请注意下面创建我的虚拟信封时安装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>
Run Code Online (Sandbox Code Playgroud)
现在查看并比较我只安装了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
Run Code Online (Sandbox Code Playgroud)