Reputation: 548
I wonder if there is a tool by which we can figure out what packages are not in used in our requirements.txt because I have tons of dependencies written in the requirements.txt but I am sure a lot of them are not in use but at the same time I am not sure as well.
Looking for some help via tools or any conventional method if thats possible.
Thanks!
Upvotes: 2
Views: 1756
Reputation: 29571
pipreqs --force
will determine all your requirements and write them to requirements.txt. Since this will only list requirements derived from your code, this will achieve the desired outcome.
Upvotes: 0
Reputation: 693
I also had tons of unused packages (until I learned how to use virtualenv properly). My requirements.txt was way too long. For me, pipreqs helped to reduce it to the packages I really need:
rm -r venv
pip install pipreqs
pipreqs --force
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip freeze > requirements.txt
Caveat: I am not an experienced programmer, I found this solution by myself and I did not check it extensively (so far), but a quick check shows that my Django project is still working.
Upvotes: 2