为什么是“-m"需要“python -m pip install ..."? [英] Why is "-m" needed for "python -m pip install ..."?
问题描述
我最近使用 pip 在 python 2.7 中安装 requests
包,但是为了这样做我不得不使用:
python -m pip 安装请求
而不仅仅是:
python pip 安装请求
这给了我一个错误:
<块引用>无法打开文件 'pip: [Errno 2] 没有那个文件或目录
为什么我需要添加-m
?
python -m pip
告诉 python 以 pip
模块作为主模块运行.>
python pip
不被理解,因为 pip 不是 python 理解的命令行参数(即,pip
是一个模块).
如果 python 脚本目录(c:\python27\scripts
for python 2.7 on windows)在你的路径上,那么你可以运行 pip
(没有 python
之前)并传递您将传递给 python -m pip
的相同选项.
所以:您需要添加 -m pip
以便 python 知道使用哪个模块作为主模块.pip
是安装在 python 脚本目录中的独立程序,不是 python 的参数.
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
?
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.
这篇关于为什么是“-m"需要“python -m pip install ..."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!