TransWikia.com

`pip install --upgrade pip` vs. `python -m pip install --upgrade pip`

Stack Overflow Asked by moth on December 17, 2020

What is the difference between:

pip install --upgrade pip

and

python -m pip install --upgrade pip

and why is python -m pip install --upgrade pip generally favoured?

3 Answers

The difference is between pip and python -m pip; the rest of the command doesn't matter. The reason to prefer the latter is that you're ensuring that the python you normally use is the one which will provide the pip module you invoke. Otherwise, there is a risk that the pip executable found in your PATH is from an unrelated or out of date Python installation; it might install packages, but your regular python invocation won't find them (because they're installed for a non-default Python).

You can also modify the second command to invoke specific Python executable names (python2.7 vs. python3.8), or even absolute paths if you might have versions with the same name installed in multiple places.

Correct answer by ShadowRanger on December 17, 2020

If i am correct, pip install --upgrade pip and python -m pip install --upgrade pip are the same unless you specify the pip or python version. The latter is preferred because it attempts to upgrade the pip associated with the specified python version (e.g. python3.7 -m pip install --upgrade pip) even if the main python version is different (python command may refer to any python version).

Answered by Shimon Cohen on December 17, 2020

The first one

pip install --upgrade pip

is to invoke pip as a command. The actual python interpretor called is not explicit. The second one is calling the python interpretor explicitly, so you know which one is called.

There should be no difference, as the __main__.py in the module and the pip script are both point to the same entry point, unless in the case that the default python is different from the one used by the pip script

Answered by adrtam on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP