What is the difference between pip install -Ur and pip install -r?

Question:

I’m trying to understand the difference between using pip install -Ur requirements.txt vs pip install -r requirements.txt I noticed that when using the one with -Ur sometimes I get more recent updated packages when compared to using -r. I tried to look it up across the internet but didn’t find a reasonable explanation. Can anyone please explain the difference?

Thanks!

Asked By: Desert Eagle

||

Answers:

pip’s official documentation says:

-U, --upgrade

Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.

So the difference is that pip install -r only installs dependencies, while -Ur also upgrades dependencies, if there is a new version available.

There’s also another reference that says:

Once you’ve got your requirements file, you can head over to a different computer or new virtual environment and run the following:

pip install -r requirements.txt

[…]
This tells pip to install the specific versions of all the dependencies listed.

To upgrade your installed packages, run the following:

pip install --upgrade -r requirements.txt

Answered By: marco-a
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.