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?
Since pip freeze shows all dependencies as a flat list, finding out which are the top level packages and which packages do they depend on requires some effort. It's also tedious to resolve conflicting dependencies that could have been installed because older version of pip didn't have true dependency resolution [1].
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.
The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements. txt. If you want to install the dependencies in a virtual environment, create and activate that environment first, then use the Install from requirements.
pip freeze might seem very useful initially but it can mess up your project because of the following reasons: It dumps all the libraries installed in your project including dependencies and sub-dependencies in the requirements. txt file. It still misses out on the libraries that are not installed using pip.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With