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

假装没事ソ 提交于 2021-02-05 12:36:11

问题


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?


回答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.




回答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




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



来源:https://stackoverflow.com/questions/63459011/pip-install-upgrade-pip-vs-python-m-pip-install-upgrade-pip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!