1

I have a script that runs pip install -r requirements.txt -t folder and executes scripts in "folder" for me.

Every time I run it pip install runs, collects all the packages and installs them with setup.py. It looks like it's not making any changes for packages that are already there and up to date but it still takes a while to collect them and run setup.py for each one. Often I'm not modifying the packages.

How can I have it skip ones that are already there? is there a way to speed this up apart from just not running pip install every time?

halfer
  • 19,824
  • 17
  • 99
  • 186
red888
  • 27,709
  • 55
  • 204
  • 392

2 Answers2

1

You can apparently select the upgrade strategy like this:

python -m pip install --requirement requirements.txt --upgrade --upgrade-strategy=only-if-needed 

Source: Ignoring some requirements when installing pip requirements

In my case it still doesn't completely do what I expect since dependencies of the updated packages will still be reinstalled, disregarding whether they are already installed and the version matches.

But it should do the trick for most cases.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • What do you mean `since dependencies of the updated packages will still be reinstalled`? It doesn't reinstall the packages, but it does reinstall their _transitive_ deps? – red888 Aug 22 '22 at 14:57
  • What I mean is that given a situation where `packageA==2.0` needs `packageB==1.0`, if your workspace state is that `packageB` is installed with version `1.0` but `packageA` is missing or a different version than `2.0`, `pip` will not only install/update `packageA@2.0`, but also it will uninstall `packageB@1.0` and reinstall it from scratch – Óscar Gómez Alcañiz Aug 23 '22 at 19:19
-1

You could take a look at :

-I, --ignore-installed Ignore the installed packages (reinstalling instead).

or

--upgrade-strategy Determines how dependency upgrading should be handled [default: only-if-needed]. "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). "only-if-needed" - are upgraded only when they do not satisfy the requirements of the upgraded package(s).

Never get into this problem before, but https://pip.pypa.io/en/stable/man/commands/install/?highlight=--ignore-installed it might help you.

Or you can do a pre-setup script that make some check before.

tsrandrei
  • 89
  • 1
  • 5