Skip to content Skip to sidebar Skip to footer

`pip Install --upgrade Pip` Vs. `python -m Pip Install --upgrade Pip`

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?

Solution 1:

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.

Solution 2:

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

Solution 3:

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).

Post a Comment for "`pip Install --upgrade Pip` Vs. `python -m Pip Install --upgrade Pip`"