1// capture requirements to install
2pip freeze > requirements.txt
3
4// install requirements from requirements.txt
5pip install -r requirements.txt
6
7// or
8$ env1/bin/pip freeze > requirements.txt
9$ env2/bin/pip install -r requirements.txt
1For Unix families: pip3 freeze > requirements.txt
2For Windos: pip freeze > requirements.txt
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