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:
- Go to your project folder and remove the virtual environment (if existant):
rm -r venv
- Install pipreqs:
pip install pipreqs
- Run pipreqs:
pipreqs --force
- Install new virtual environment:
python3 -m venv venv
- Activate it:
source venv/bin/activate
- Install required modules:
pip install -r requirements.txt
- 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.