如何在 macOS 或 OS X 上安装 pip?
昨天我花了大部分时间寻找安装 pip
(Python 包管理器)的明确答案.我找不到好的解决方案.
I spent most of the day yesterday searching for a clear answer for installing pip
(package manager for Python). I can't find a good solution.
如何安装?
pip 的文档列出了支持的安装机制:https://pip.pypa.io/en/stable/installation/#supported-methods
pip's documentation lists the supported mechanisms to install it: https://pip.pypa.io/en/stable/installation/#supported-methods
通常建议避免在操作系统提供的 python
命令上安装 pip,并通过 https://python.org 安装程序或使用类似 Homebrew 或 pyenv.
It is generally recommended to avoid installing pip on the OS-provided python
commands, and to install Python via the https://python.org installers or using something like Homebrew or pyenv.
Python 3.4+ 将具有 ensurepip
,因此如果您无法运行 python3 -m pip
-- 运行 python3 -m ensurepip
它会为您安装 pip.
Python 3.4+ will have ensurepip
, so if you're unable to run python3 -m pip
-- run python3 -m ensurepip
and it'll install pip for you.
如果您使用的是停产版本的 Python,您可以使用 get-pip.py
代替.
If you're using an end-of-life version of Python, you can use get-pip.py
instead.
旧答案(过时,导致安装损坏)
easy_install pip
如果您需要管理员权限来运行此程序,请尝试:
If you need admin privileges to run this, try:
sudo easy_install pip