mrQWERTY
mrQWERTY

Reputation: 4149

Python - Pip install requirements only if dependencies are not satisifed

I am wondering about this command pip install -r requirements.txt. Does pip install modules if they are not satisfied or does it try and install anyway even if the modules are already there? If it is the latter, than is there any way to write a shell script which checks if dependencies are satisfied and if not invoke pip install?

Upvotes: 2

Views: 3137

Answers (1)

Thomas Orozco
Thomas Orozco

Reputation: 55303

Pip only installs packages that are not installed yet.

This does mean that even if a new version is available, old packages will be kept. You can pass the --upgrade flag to prevent that behavior and install the latest versions (but then pip will call pypi for every package in your requirements file, in order to identify its latest version).

An alternative is to have version specifiers in your requirements file (e.g. mypackage==1.2.3), so that if you change your requirements file and use new versions, pip will pick those up without the --upgrade flag.

Upvotes: 4

Related Questions