1For Unix families: pip3 freeze > requirements.txt
2For Windos: pip freeze > requirements.txt
1# First:
2pip install pipreqs
3
4# Then:
5pipreqs path/to/project
6
7# There is now a requirements.txt file in the project folder.
1import subprocess
2result = subprocess.run(["pip", "freeze"], capture_output=True, text=True, shell=True)
3with open('requirements.txt', 'w') as d:
4 for line in result.stdout.split('\n'):
5 d.write(line.split('==')[0]+'\n')
6 # ".split('==')[0]" seperates name from version