2

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!

Harshit verma
  • 506
  • 3
  • 25

1 Answers1

2

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:

  1. Go to your project folder and remove the virtual environment (if existant): rm -r venv
  2. Install pipreqs: pip install pipreqs
  3. Run pipreqs: pipreqs --force
  4. Install new virtual environment: python3 -m venv venv
  5. Activate it: source venv/bin/activate
  6. Install required modules: pip install -r requirements.txt
  7. Build the complete list which includes the dependencies: 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.

Ralf Zosel
  • 683
  • 1
  • 7
  • 26