Search code examples
pip

Hide "Requirement already satisfied" warning


We have a shell script that automatically prepares virtual environment and then runs tests in it. Part of the script installs requirements:

pip install -r requirements.txt

When the script is run multiple times it prints a warning for each requirement:

Requirement already satisfied (use --upgrade to upgrade): discover==0.4.0
...

I need to run the installation step every time in case that someone adds a new requirement. I understand why the warning is displayed. The problem is that it clutters the test output.

Is there a way how to disable/hide this warning?


Solution

  • Assuming the errors go to stderr, this bash code should do it:

    pip install -r requirements.txt 2> >(grep -v 'Requirement already satisfied' 1>&2)
    

    For more recent versions of 'pip', where errors go to stdout, the above can be simplified to:

    pip install -r requirements.txt | grep -v 'already satisfied'