Managing contents of requirements.txt for a Python virtual environment

One good thing here is you are using virtualenv, which will make your task very easy.

  1. Activate virtualenv ($source path_to_virtualenv/bin/activate)

  2. Go to your project root directory

  3. Get all the packages along with dependencies in requirements.txt

    pip freeze > requirements.txt
    
  4. You don't have to worry about anything else apart from making sure next person installs the requirements recursively by following command

    pip install -r requirements.txt
    

Both approaches are valid and work. But there is a little difference. When you enter all the dependencies in the requirements.txt you will be able to pin the versions of them. If you leave them out, there might be a later update and if Flask has something like Werkzeug>=0.11 in its dependencies, you will get a newer version of Werkzeug installed.

So it comes down to updates vs. defined environment. Whatever suits you better.


You can (from your active virtual environment) do the following

pip freeze > requirements.txt

which'll automatically take care of all libraries/modules available in your project.

The next developer would only have to issue:

pip install -r requirements.txt