Arian
Arian

Reputation: 7719

pip install & uninstall recursively in non-interactive mode

As a part of my bash script, I want to install and uninstall pip dependencies that I have their names in a file in a non-interactive mode. I was able to search around and find these commands:

pip3 uninstall --yes -r host-requirements.txt
pip3 install --no-input -r host-requirements.txt

I wasn't able to find --yes & --no-input options in the help doc of pip, and I'm not sure if they are officially supported.

Upvotes: 26

Views: 35560

Answers (3)

Anurag Saxena
Anurag Saxena

Reputation: 468

For uninstall, you can use the --yes or -y flag as described here: https://pip.pypa.io/en/stable/cli/pip_uninstall/

For installation, you can pass a yes | pip install -r requirements.txt as described here: python pip silent install

Hope this helps.

Upvotes: 26

Rich Andrews
Rich Andrews

Reputation: 1670

A common issue on install is if there is a private repository dependency that has to be resolved and the key of the remote server has to be initially added.

Obtaining file://...
Collecting your_private_package@ git+ssh://...
  Cloning ssh://****@.../
  Running command git clone -q 'ssh://****@.../
The authenticity of host can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)?

For this, ssh StrictHostKeyChecking would be temporarily set to no. This can be done at the host or user level at the risk of less security.

Upvotes: 1

Bartosz Dabrowski
Bartosz Dabrowski

Reputation: 1860

There are more interactive questions that expect other answers than "yes". For instance:

Directory /opt/services/spam/egg already exists, and is not a git clone.
What to do?  (i)gnore, (w)ipe, (b)ackup`

In such scenario I found calling echo "i" | pip install ... was sufficient.

Upvotes: 2

Related Questions