How to run pip in non-interactive mode?

54,145

Solution 1

There is a --yes option specifically for the uninstall command. Calling

pip uninstall --yes <some-package>

uninstalls the package without asking for confirmation.

For installing, piping in the yes command still seems to be the way to go.

Another approach that might be overkill depending on your use case is using a dedicated tool. This is definitely the way to go, if one struggles with automatic installation and configuration on a regular basis. As an example: SaltStacks state system has tons of ways to automate interaction with pip. This is not only for orchestrating server farms, but can be used locally as well by running salt-call directly. See the introduction about running salt masterless.

Solution 2

With recent versions of setuptools (pip version >= 20.2), you can use:

pip install --no-input ...

… which will disable prompting user for private repo credentials.

Solution 3

I'm far from a python/pip expert, but I have used it for various purposes for several years and have yet to encounter a straight forward use of pip install that is interactive. It does have extensive options for less straight forward case (alternate package indices, caching, dev mode, etc,). If you have a specific install case that requires some interaction, my guess is you could automate it by providing the correct combination of specialized options, documented here.

Uninstall is the case I'm much more used to requiring interaction (includes an explicit confirmation to remove modules), and it does in fact support the standard --yes flag you refer to in the question.

Share:
54,145

Related videos on Youtube

vladimir
Author by

vladimir

Updated on September 18, 2022

Comments

  • vladimir
    vladimir over 1 year

    Most of tools I'm using have some mode (often ON by default) where they ask me zero questions while running the command. apt-get is an example close to pip. There's -y option which makes it non-interactive. Is there any such option for pip? If there's no such option how to wrap it into some script which will achieve what I want. For example I would like to run something like:

    pipyes install mypackage
    

    Currently I'm doing this, but would like to wrap it into script:

    yes | pip install mypackage
    

    Is it "correct" way to achieve pip non-interactive mode.

  • Otzen
    Otzen over 3 years
    Yes is old post, but for any scavengers passing by, the correct option (that worked for me in pip version 20.0.2) is --no-input