pip freeze without dependencies of installed packages

PythonPiprequirements.txt

Python Problem Overview


When I do pip freeze I get the packages I've explicitly installed plus those packages that are dependencies of those packages.

For example:

$ pip install fabric
...
$ pip freeze
Fabric==1.0.1
paramiko==1.7.6
pycrypto==2.3

Ok fine but then I move to install this requirements.txt on another environment with pip install I'd get the same result with the last 2 lines removed.

So my question is: how I can I create the most simplified requirements.txt where all calculable dependencies are not shown?

Python Solutions


Solution 1 - Python

Now there is (disclaimer: I did it).

All you need is to install pip-chill from PyPI and run pip-chill from your Python environment.

If you are feeling adventurous and don't want to pin versions (or want to use pip-compile), you can use pip-chill --no-version and it'll give you the minimal requirements for your current environment.

https://github.com/rbanffy/pip-chill

Solution 2 - Python

There is no way to create "the most simplified requirements.txt" with pip - and I don't know if you would need it in this case.

It is good to have all packages in the requirements.txt, because you are sure about what dependencies versions work with your environment.

Think about paramiko getting updated, and breaking backwards compatibilities: you would have problems.

Solution 3 - Python

I think the simply way to remove version is cut -d"=" -f1 after having run pip freeze.

pip3 freeze | cut -d"=" -f1 

Solution 4 - Python

pipdeptree is another option.

It produces full requirements.txt (with pipdeptree -f) like this:

jupyter==1.0.0
  ipykernel==5.4.3
    ipython==7.19.0
      backcall==0.2.0
      decorator==4.4.2
      jedi==0.17.2
        parso==0.7.1

This file serves two purposes:

  • Used as a traditional requirements.txt fed to pip install;
  • Used as a developer-friendly packages list (like the one created by pip-chill) simply with grep '^\w' requirements.txt.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTom VinerView Question on Stackoverflow
Solution 1 - PythonrbanffyView Answer on Stackoverflow
Solution 2 - PythonHugo TavaresView Answer on Stackoverflow
Solution 3 - PythonhaulpdView Answer on Stackoverflow
Solution 4 - PythonLeoView Answer on Stackoverflow