Search code examples
pythondependenciespython-importrequirements.txt

Automatically create file 'requirements.txt'


Sometimes I download the Python source code from GitHub and don't know how to install all the dependencies. If there isn't any requirements.txt file I have to create it by hand.

Given the Python source code directory, is it possible to create requirements.txt automatically from the import section?


Solution

  • Use Pipenv or other tools is recommended for improving your development flow.

    pip3 freeze > requirements.txt  # Python3
    pip freeze > requirements.txt  # Python2
    

    If you do not use a virtual environment, pigar will be a good choice for you.