grep output to pip install - bash

How to take a subset of python dependencies in requirements.txt and using grep send them to pip install?
Let's say I want to install redis and gunicorn only: with
cat requirements.txt | grep "redis\|gunicorn"
I get only the dependencies I want,
redis>=3.5.3
gunicorn>=20.1.0
but I would like to pass it as requirement file to pip install.
I guess I should create a temp file with the output of grep and do something like pip install -r tempfile, but I don't understand how to do it.
Could anyone help me?

You can use xargs to pass the outputs to pip:
grep "redis\|gunicorn" requirements.txt | xargs pip install

Related

what is the meaning of pip install -v?

Recently, I seen a command of pip install -v
actually it is
$ git clone https://github.com/NVIDIA/apex
$ cd apex
$ pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
I usually command pip install something
But what is pip install -v?
-v or we can can also use --verbose. Both are same.
-v is used when you want to use or expressed something in more words than are needed.
-v Give more output. Option is additive, and can be used up to 3 times.

Automatically update outdated pip3 packages with bash scripts

I have a bash script to automatically update pip3 packages:
It is one line script:
pip3 list --outdated | cut -d' ' -f1 | xargs pip3 install --upgrade
and it has always worked.
Now (maybe after the upgrade to Ubuntu 18.04) it is not working anymore apparently because of a wrong usage of pip3 install.
What is wrong with the script?
Looks like headers of the pip3 list are causing failure in installation of package.
You can trim those header lines by using tail.
pip3 list --outdated | cut -d' ' -f1 | tail -n+3 | xargs pip3 install --upgrade
tail -n+3 removes the header and boundary line which only gives package names to xargs.

remove multiple rpm packages using one bash command

I'd like to use a single bash command to uninstall several packages.
# rpm -qa | grep php
php-common-5.4.16-45.el7.x86_64
php-5.4.16-45.el7.x86_64
php-mysql-5.4.16-45.el7.x86_64
php-pdo-5.4.16-45.el7.x86_64
php-cli-5.4.16-45.el7.x86_64
will give me an output of all the pakcages I'd like to remove, however, how can I pipe that into a remove package command? Something like this:
# rpm -qa | grep php | yum remove ${package}
I tried this and it worked.
rpm -qa | grep php | while read -r line; do yum remove -y $line; done

Hide "Requirement already satisfied" warning

We have a shell script that automatically prepares virtual environment and then runs tests in it. Part of the script installs requirements:
pip install -r requirements.txt
When the script is run multiple times it prints a warning for each requirement:
Requirement already satisfied (use --upgrade to upgrade): discover==0.4.0
...
I need to run the installation step every time in case that someone adds a new requirement. I understand why the warning is displayed. The problem is that it clutters the test output.
Is there a way how to disable/hide this warning?
It worked for me:
pip install -r requirements.txt | grep -v 'already satisfied'
Assuming the errors go to stderr, this bash code should do it:
pip install -r requirements.txt 2> >(grep -v 'Requirement already satisfied' 1>&2)
For more recent versions of 'pip', where errors go to stdout, the above can be simplified to:
pip install -r requirements.txt | grep -v 'already satisfied'
For Windows users landing here this can be resolved in a virtually similar manner using Find
pip install -r requirements.txt | find /V "already satisfied"
and as answered in a Windows specific question the other way is
pip install -r requirements.txt | findstr /V /C:"Requirement already satisfied"

Will this bash loop apt-get install all my anaconda packages?

I don't want to just try it and mess something up.
$ dlpackages=$(ls -l anaconda3/bin | awk '{print $9}')
$ for package in $dlpackages; do sudo apt-get install $package; done
or as root: $ for package in $dlpackages; do apt-get install $package; done
Add a safety check for each package, to see if it can be located.
dlpackages=$(ls -l anaconda3/bin | awk '{print $9}')
for package in $dlpackages; do
[[ $(apt-cache search $package) ]] && sudo apt-get install $package
done
Now for every string, the install will only be executed if the package can be found.
Alternatively use the -s option of install as Eric Renouf suggested.
In general things in bin aren't the same as package names. conda list may be closer, but you'll ultimately probably have to figure out the translation of package names manually.

Resources