pip assists in creating requirements.txt files by providing the [freeze](<https://pip.pypa.io/en/stable/reference/pip_freeze/#cmdoption-l>) option.

pip freeze --local > requirements.txt

The [--local](<https://pip.pypa.io/en/stable/reference/pip_freeze/#cmdoption-l>) parameter will only output a list of packages and versions that are installed locally to a virtualenv. Global packages will not be listed.