Create requirements.txt without pip freeze

0xkoji - May 12 '19 - - Dev Community

This is completely useless for people since we can use pip freeze > requirements.txt to create a requirements.txt lol

But here is the code to do that without pip freeze command

import pkg_resources
OUTPUT_FILE = 'requirements.txt'
with open(OUTPUT_FILE, mode='w') as f:
    for dist in pkg_resources.working_set:
        requirement = dist.project_name + '==' + dist.version
        f.write(requirement + '\n')

Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .