The Python Oracle

Pip freeze vs. pip list

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Luau

--

Chapters
00:00 Question
00:31 Accepted answer (Score 159)
01:36 Answer 2 (Score 63)
02:13 Answer 3 (Score 59)
02:56 Answer 4 (Score 31)
03:43 Thank you

--

Full question
https://stackoverflow.com/questions/1896...

Accepted answer links:
[Virtualenv and pip Basics]: http://jonathanchu.is/posts/virtualenv-a.../
[Requirements File Format]: https://pip.pypa.io/en/stable/cli/pip_in.../

Answer 2 links:
[the documentation]: https://pip.pypa.io/en/stable/reference/...

Answer 4 links:
[pip documentation]: http://staticbackup.readthedocs.com/pip/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pip

#avk47



ACCEPTED ANSWER

Score 195


One may generate a requirements.txt via:

$ pip freeze > requirements.txt

A user can use this requirements.txt file to install all the dependencies. For instance:

$ pip install -r requirements.txt

The packages need to be in a specific format for pip to understand, such as:

# requirements.txt
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.




ANSWER 2

Score 75


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




ANSWER 3

Score 63


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.




ANSWER 4

Score 31


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.