Why is “-m” needed for “python -m pip install …”?

这一生的挚爱 提交于 2021-02-07 09:46:51

问题


I recently used pip to install the requests package in python 2.7, however in order to do so I had to use:

python -m pip install requests 

instead of just:

python pip install requests

which gave me an error:

can't open file 'pip: [Errno 2] No such file or directory

Why did I need to add the -m?


回答1:


python -m pip tells python to run with the pip module as the main module.

python pip isn't understood, because pip isn't a command line argument that python understands (i.e., pip is a module).

If the python scripts directory (c:\python27\scripts for python 2.7 on windows) is on your path, then you can just run pip (without python before it) and pass the same options you would pass to python -m pip.

So: you need to add -m pip so python knows what module to use as the main module. pip is a standalone program installed in your python scripts directory, not an argument to python.



来源:https://stackoverflow.com/questions/40392499/why-is-m-needed-for-python-m-pip-install

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