pip install & uninstall recursively in non-interactive mode

Question:

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.

Asked By: Arian

||

Answers:

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.

Answered By: Anurag Saxena

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.

Answered By: Bartosz Dabrowski

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.

Answered By: Rich Andrews
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.