Tue Jul 25 2023
2 min readJust add direct dependencies to requirements.txt, automatically.
🙏Namaste Pythonistas! Let me ask you something — how do you usually maintain your requirements.txt
file? If you’re like me, you must be using good ol’ pip freeze > requirements.txt
command. Sure, it’s quick and easy, but have you ever found yourself looking at the file later and wondering what on earth cffi==1.15.1
refers to? Have you struggled to figure out if it was installed directly or as a dependency of another package? The ideal way would be to “hand write” it, but who has the time for it!?
Well, let me tell you about pip-chill
. It’s like a smarter version of pip freeze
. Instead of simply dumping all installed packages into the requirements file, it shows only the ones you directly installed.
To get started, just install pip-chill
using pip
itself:
After that here is how I generate the requirements.txt
file now:
--no-chill
: does not include pip-chill
itself in the output-v
: outputs the indirect dependencies as well, but commented. Therefore it is easy to keep track of them.It generates the following for a basic Django project.
See how pretty it looks. It just works and solves my problem of properly maintaining requirements.txt
. Now, I can focus on coding and building cool stuff, leaving the hassle of maintaining the requirements file to pip-chill
.
So just, take a chill pill with pip-chill and chillax!
Happy coding 👋.
Disclaimer: Assistance from generative AI tools was used for this post.