Hide "Requirement already satisfied" warning - pip

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"

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

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.

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

How can I make dpkg automatically choose my own virtual package over an already installed one?

I have several packages that provide the same functionality - and in the device
'there can be only one' at the same time.
I have read about the 'Provides, Conflicts, Replaces' in the debian policy, but I have not found a way (using dpkg with commands/switches) to automatically replace an already installed virtual package without removing it manually first.
My package's control file specifies the following for all the packages in question:
Provides: myown-virtual-package
Conflicts: myown-virtual-package
Replaces: myown-virtual-package
Here is what I do, It seems to work, but I was wondering if there is a standard way using only dpkg
# remove any conflicting virtual packages
for i in /tmp/upgrade_software/*.deb
do
# find out what package name and what it provides
provides_line=$(dpkg --info $i | grep "^ Provides: ")
package_line=$(dpkg --info $i | grep "^ Package: ")
virt_package=${provides_line##*: }
this_package=${package_line##*: }
# skip if it is not a virtual package
[ -z "${virt_package}" ] && continue
# remove any package that provides the same
otherpackage_line=$(dpkg-query -W -f='${Provides}: ${Package}\n' \
| grep "${virt_package}:" | grep -v ${this_package})
if [ -n "${otherpackage_line}" ] ; then
otherpackage=${otherpackage_line##*: }
echo " ------ removing ${otherpackage} because of conflict -------"
dpkg --purge ${otherpackage}
echo " -------------"
fi
echo \'$virt_package\' checked for conflicts
done
Thanks in advance, jj
dpkg will not take this kind of automatic conflict resolution measures. For these tasks, there is apt-get and aptitude. It may just work with
dpkg -i package.deb ; apt-get -f install
The latter command is supposed to resolve the conflicts. If it opts to remove your own package for resolution, you may even want to try
dpkg -i package.deb ; apt-get -f install <package>
I.e., tell apt to install your package (without a .deb extension) as it should now be visible to apt.
This can be done with dpkg alone, by giving it enough information so that it can perform the operation. The way to prepare dpkg for this is via selections.
In this case you'd tell that removing the old provider is ok, and then when you install the new one dpkg will be able to remove the other package during the upgrade.
Try something like:
echo old-provider deinstall | dpkg --set-selections
dpkg -iB new-provider.deb
That should in principle do it, and no need for apt-get fixing it up (-f), or for pre purges (possibly with --force options if there are packages depending on the virtuals).

Auto-install packages from inside makefile

Goal: when the user types 'make packages', automatically search for the package libx11-dev (required for my program to compile) and, if not found, install it. Here's a stripped-down version of my makefile:
PACKAGES = $(shell if [ -z $(dpkg -l | grep libx11-dev) ]; then sudo apt-get install libx11-dev; fi)
[other definitions and targets]
packages: $(PACKAGES)
When I type 'make packages', I'm prompted for the super-user password. If entered correctly, it then hangs indefinitely.
Is what I'm trying to do even possible from within the makefile? If so, how?
Thanks so much.
The problem is that the shell function acts like backticks in the shell: it takes the output to stdout and returns it as the value of the function. So, apt-get is not hanging, it's waiting for you to enter a response to some question. But you cannot see the question because make has taken the output.
The way you're doing this is not going to work. Why are you using shell instead of just writing it as a rule?
packages:
[ -z `dpkg -l | grep libx11-dev` ] && sudo apt-get install libx11-dev
.PHONY: packages
I figured out a better way, which avoids the problem of having unexpected arguments to the if statement:
if ! dpkg -l | grep libx11-dev -c >>/dev/null; then sudo apt-get install libx11-dev; fi
The -c flag on grep makes it return the number of lines in dpkg -l which contain the string libx11-dev, which will either be 0 (if uninstalled) or 1 (if installed), allowing
dpkg -l | grep libx11-dev -c
to be treated like an ordinary boolean variable.

Resources