Automatically update outdated pip3 packages with bash scripts - bash

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.

Related

grep output to pip install

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

upgrade all outdated pip packages discarding failures [duplicate]

This question already has answers here:
How to upgrade all Python packages with pip
(56 answers)
Closed 4 years ago.
I have a bash command to upgrade all pip packages that I installed.
The command is:
pip3 list --outdated | cut -d' ' -f1 | tail -n +3 | xargs pip3 install --upgrade
The problem is that if one of the packages fails to upgrade, it rolls back deleting the upgrades of the ones that were successful upgraded.
Is there a way to upgrade all outdated packages with a single command discarding the failures of some packages?
I slightly modified the command posted in the duplicate of link.
pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U --user

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"

scripting yum to install a list of packages

I am having trouble getting yum to work with a list of packages I want to install. I've tried:
yum -y install $(cat /home/pkglist.txt)
and
for i in cat pkglist.txt; do yum -y install $i; done
and
yum -y install $(cat pkglist.txt | tr '\n' ' ' | tr '\r' ' ')
but none of them install the packages.
All I get back is:
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
available.perl-CPAN
available.cpp
available.fontconfig
available.gcc
available.gd
available.net-snmp-libs
available.mailcap
available.perl-libwww-perl
available.perl-XML-LibXML
available.perl-DateTime
available.perl-Time-HiRes
available.make
available.net-snmp-perl
available.perl-Test-Pod
available.perl-Net-SSLeay
available.expat-devel
available.expat
Error: Nothing to do
Thanks in advance! -Luke
You can this-
cat /home/pkglist.txt | xargs yum -y install

Resources