pip3和python3 -m pip之间的区别 [英] Difference between pip3 and python3 -m pip
问题描述
我正在尝试使用pip和python3安装一些软件包.我使用的是MacOS,因此默认情况下,当我运行pip时,它将使用我的Python 2版本.
I am trying to install some packages using pip and python3. I am using MacOS, so by default when I run pip, it uses my version of Python 2.
我已经能够通过使用以下命令在python 3中安装软件包:
I have been able to install a package in python 3 by using:
$ pip3 install package_name
但是,我能够做到(至少看起来如此):
However, I am able to do the same by (at least it seems):
$ python3 -m pip install package_name
我想知道pip3
和python3 -m pip
是否具有相同的效果.
I wonder whether or not pip3
and python3 -m pip
have the same effect.
推荐答案
它们是相同的.如果您查看bin文件夹中的pip3文件,它将从pip模块调用main
函数.
They are the same. If you look at the pip3 file in the bin folder it calls the main
function from the pip module.
pip3 install package_name
在bin文件夹中运行pip3文件:
pip3 install package_name
runs pip3 file in the bin folder:
# bin/pip3
# or bin/pip if using pip install package_name
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
python3 -m pip install package_name
运行 pip
python3 -m pip install package_name
runs the __init__.py
file of the pip module.
# pip/__init__.py
if __name__ == '__main__':
sys.exit(main())
它们都运行相同的main()
函数
这篇关于pip3和python3 -m pip之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!