Automatically create requirements.txt Automatically create requirements.txt python python

Automatically create requirements.txt

You can use the following code to generate a requirements.txt file:

pip install pipreqspipreqs /path/to/project

more info related to pipreqs can be found here.

Sometimes you come across pip freeze, but this saves all packages in the environment including those that you don't use in your current project.

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

pip3 freeze > requirements.txt  # Python3pip freeze > requirements.txt  # Python2

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

In my case, I use Anaconda, so running the following command from conda terminal inside my environment solved it, and created this requirements.txt file for me automatically:

conda list -e > requirements.txt

This was taken from this Github link pratos/condaenv.txt

If an error been seen, and you are using anaconda, try to use the .yml option:

conda env export > <environment-name>.yml

For other person to use the environment or if you are creating a new enviroment on another machine:

conda env create -f <environment-name>.yml

.yml option been found here