0

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!

Desert Eagle
  • 191
  • 14
  • `-U` = `--upgrade`: "*Upgrade all packages to the newest available version. This process is recursive regardless of whether a dependency is already satisfied.*". Your first choice when not knowing what a command line option is doing should be `pip --help`/`man pip`. – mozway Dec 17 '22 at 03:24
  • There is no specific "-Ur". Those are 2 _separate_ options, `-U` and `-r`. You see more updates because `-U` gets applied to all the packages listed in requirements.txt. – Gino Mempin Dec 17 '22 at 03:30
  • Does this answer your question? [What does the "-U" option stand for in pip install -U](https://stackoverflow.com/questions/12435209/what-does-the-u-option-stand-for-in-pip-install-u) – Gino Mempin Dec 17 '22 at 03:30
  • Here's what I got when I use the `-U` by itself: ```$ pip install -U requirements.txt Defaulting to user installation because normal site-packages is not writeable ERROR: Could not find a version that satisfies the requirement requirements.txt (from versions: none) HINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txt ERROR: No matching distribution found for requirements.txt``` – Desert Eagle Dec 17 '22 at 03:34

1 Answers1

1

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

Marco
  • 7,007
  • 2
  • 19
  • 49