python pip全称,“ pip install”和“ pip install”之间有什么区别和“ python -m pip install”?...

I have a local version of Python 3.4.1 and I can run python -m pip install, but I'm unable to find the pip binary to run pip install. What's the difference between these two?

解决方案

2014

They do exactly the same thing. In fact, the docs for distributing Python modules were just updated to suggest using python -m pip instead of the pip executable, because it's easier to tell which version of python is going to be used to actually run pip that way.

Here's some more concrete "proof", beyond just trusting my word and the bug report I linked :)

If you take a look at the pip executable script, it's just doing this:

from pkg_resources import load_entry_point

load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()

It's calling load_entry_point, which returns a function, and then executing that function. The entry point it's using is called 'console_scripts'. If you look at the entry_points.txt file for pip (/usr/lib/python2.7/dist-packages/pip-1.5.4.egg-info/entry_points.txt on my Ubuntu machine), you'll see this:

[console_scripts]

pip = pip:main

pip2.7 = pip:main

pip2 = pip:main

So the entry point returned is the main function in the pip module.

When you run python -m pip, you're executing the __main__.py script inside the pip package. That looks like this:

import sys

from .runner import run

if __name__ == '__main__':

exit = run()

if exit:

sys.exit(exit)

And the runner.run function looks like this:

def run():

base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

## FIXME: this is kind of crude; if we could create a fake pip

## module, then exec into it and update pip.__path__ properly, we

## wouldn't have to update sys.path:

sys.path.insert(0, base)

import pip

return pip.main()

As you can see, it's just calling the pip.main function, too. So both commands end up calling the same main function in pip/__init__.py.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值