30

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.

3 Answers 3

32

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.

3
  • --no-input and --yes options are all gone in the pip 24.0 version. Commented Apr 18 at 22:09
  • @JackOuttaBox I just tried it with 24.0 and pip uninstall --yes works exactly as expected. It still is documented and I don't think this will ever go away. Can you elaborate what brought you to the believe that this is gone? Commented Apr 22 at 11:58
  • @JackOuttaBox I wasn't aware of --no-input but I also think that in the case of pip uninstall is the wrong way to go about it. I tried pip uninstall --no-input and I got a nasty exception (Exception: No input was expected ($PIP_NO_INPUT set); question: Proceed (Y/n)?). It also makes sense to me: no input indicates you don't want to interact, but you need to confirm the de-installation, so input (or --yes) is necessary to proceed sensibly. Commented Apr 22 at 12:01
15

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.

1
  • 4
    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
    – Otzen
    Commented Dec 11, 2020 at 16:02
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .