“python.exe -m pip install”相对于”pip install”命令的优势是什么?

huangapple go评论115阅读模式
英文:

What are the advantages of "python.exe -m pip install" over "pip install" command?

问题

我在使用 `pip install --upgrade pip` 时收到上面的消息,但当我使用通知中提到的 `python.exe -m pip install --upgrade pip` 时,pip被升级了。

有人能告诉我这两个命令之间的区别吗?
英文:
        C:\Users\hp>pip install --upgrade pip
        Requirement already satisfied: pip in 
        c:\users\hp\appdata\local\programs\python\python311\lib\site-packages (23.1.2)
        Collecting pip
         Downloading pip-23.2.1-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 10.2 MB/s eta 0:00:00
        ERROR: To modify pip, please run the following command:
        C:\Users\hp\AppData\Local\Programs\Python\Python311\python.exe -m pip install -- 
       upgrade pip

        [notice] A new release of pip is available: 23.1.2 -> 23.2.1
        [notice] To update, run: python.exe -m pip install --upgrade pip

I get the above message when using pip install --upgrade pip, but when I use python.exe -m pip install--upgrade pip as mentioned in the notice, pip gets upgraded.

Can anyone tell me the difference between these two commands?

答案1

得分: 1

pip 无法在 pip.exe 已经运行时更新 pip.exe,因此您需要使用一个命令来避免在 Windows 上运行 pip.exe 可执行文件以更新 pip 本身。Unix 平台没有这个限制。

英文:

pip can't update pip.exe if pip.exe is already running, so you need to use a command that avoids running the pip.exe executable to update pip itself on Windows. Unix platforms don't have this limitation.

答案2

得分: 1

pip install --upgrade pip:
这个命令将尝试升级当前活动的 Python 环境中的 pip。如果您有多个 Python 安装并且不在虚拟环境中工作,它可能不会升级您期望的 pip(例如,如果 pip 被别名到不同的 Python 安装)。

python.exe -m pip install --upgrade pip:
这个命令将升级 python.exe 指向的特定 Python 解释器的 pip。如果您安装了多个版本的 Python,通常更可靠的方法是使用这种形式,因为您可以通过将 python.exe 替换为 python3.8、python3.9 等来指定要升级 pip 的 Python 解释器。

英文:

pip install --upgrade pip:
This command will attempt to upgrade pip in your currently active Python environment. If you have multiple Python installations and you're not working inside a virtual environment, it might not upgrade the pip you expect (e.g., if pip is aliased to a different Python installation).

python.exe -m pip install --upgrade pip:
This command will upgrade pip for the specific Python interpreter that python.exe points to. If you have multiple versions of Python installed, it's often more reliable to use this form because you can specify which Python interpreter you want to upgrade pip for by replacing python.exe with python3.8, python3.9, etc.

huangapple
  • 本文由 发表于 2023年7月24日 17:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753043.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定