how to create requirements.txt python code example

Example 1: command to make requirements.txt

pip freeze > requirements.txt

Example 2: pip install from requirements.txt

$ pip install -r requirements.txt

Example 3: pip freeze requirements.txt

$ env1/bin/pip freeze > requirements.txt
$ env2/bin/pip install -r requirements.txt

Example 4: how to generate requirements.txt django

For Unix families: pip3 freeze > requirements.txt
For Windos: pip freeze > requirements.txt

Example 5: install requirements.txt in pip command

note: yor should be on the same dir as requirements.txt file 

pip install -r requirements.txt

Example 6: python generate requirements.txt

# First:
pip install pipreqs

# Then:
pipreqs path/to/project

# There is now a requirements.txt file in the project folder.