繁体   English   中英

'pip install 和有什么区别<package> ' 和 'python -m pip 安装<package> '?</package></package>

[英]What is the difference between 'pip install <package>' and 'python -m pip install <package>'?

在哪种情况下,人们会使用一种方法而不是另一种方法? 这两种方法都有缺点吗?

我已经看过这两种方法,但我不知道两者之间的区别是什么,我似乎无法找到该问题的答案。 行为有差异吗? 还是一个只是另一个的进化版本?

例如, 这里两种方法都在所有答案中使用。

注意:这里似乎也有一个非常相似的问题,但是这个问题只涉及在使用python -m pip install <package>时提供-m的必要性,但不涉及上述两种方法之间的差异。

pip install...调用pip可执行文件,该可执行文件必须在您的路径中。 python -m pip... the pip application that corresponds to this python installation (ie Python will use its normal import mechanism to resolve the pip package).

通常这两种方法是相同的,但是想想alias pip=echo之后会发生什么; python -m pip...方法仍然有效。

For example you can use the python -m pip... approach if you're inside a virtual environment, but you want to install a package into another Python installation:

(somevenv) $ pip install ...   # installs into 'somevenv'
(somevenv) $ /path/to/othervenv/bin/python -m pip install ...  # installs into 'othervenv'

In the end, python -m pip... is always going to use the 'correct' installation of Python, assuming that you intended to use whatever python points to.

如果要从运行脚本中安装分发,则根据pip 文档,使用python -m pip方法也是首选方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM