Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install & uninstall recursively in non-interactive mode

Tags:

python

pip

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.

like image 549
Arian Avatar asked May 30 '19 17:05

Arian


3 Answers

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

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

Hope this helps.

like image 169
Anurag Saxena Avatar answered Oct 12 '22 04:10

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.

like image 34
Bartosz Dabrowski Avatar answered Oct 12 '22 04:10

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.

like image 27
Rich Andrews Avatar answered Oct 12 '22 05:10

Rich Andrews