pip freeze without dependencies of installed packages

Question:

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?

Asked By: Tom Viner

||

Answers:

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.

Answered By: Hugo Tavares

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

Answered By: rbanffy

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.
Answered By: Leo

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

pip3 freeze | cut -d"=" -f1 
Answered By: haulpd
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.