Python 如何在 macOS 或 OS X 上安装 pip?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17271319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install pip on macOS or OS X?
提问by The System
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(Python 的包管理器)。我找不到好的解决方案。
How do I install it?
我该如何安装?
回答by Leigh
You can install it through Homebrew on OS X. Why would you install Python with Homebrew?
你可以在 OS X 上通过 Homebrew 安装它。你为什么要用 Homebrew 安装 Python?
The version of Python that ships with OS X is great for learning but it's not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version. (source)
OS X 附带的 Python 版本非常适合学习,但不适合开发。OS X 附带的版本可能与官方当前的 Python 版本过时,该版本被认为是稳定的生产版本。(来源)
Homebrew is something of a package manager for OS X. Find more details on the Homebrew page. Once Homebrew is installed, run the following to install the latest Python, Pip & Setuptools:
Homebrew 是 OS X 的包管理器。在Homebrew 页面上找到更多详细信息。安装 Homebrew 后,运行以下命令来安装最新的 Python、Pip 和 Setuptools:
brew install python
回答by Scott Tesler
UPDATE (Jan 2019):
更新(2019 年 1 月):
easy_installhas been deprecated. Please use get-pip.pyinstead:
easy_install已被弃用。请get-pip.py改用:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Old answer:
旧答案:
easy_install pip
If you need admin privileges to run this, try:
如果您需要管理员权限来运行它,请尝试:
sudo easy_install pip
回答by tpham
$ sudo port install py27-pip
Then update your PATH to include py27-pip bin directory (you can add this in ~/.bash_profile PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
然后更新您的 PATH 以包含 py27-pip bin 目录(您可以将其添加到 ~/.bash_profile PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
pip will be available in new terminal window.
pip 将在新的终端窗口中可用。
回答by 42wolf
You should install Brew first:
您应该先安装 Brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then brew install Python
然后 brew install Python
brew install python
Then pipwill work
然后pip会工作
回答by Florent Bruneau
The simplest solution is to follow the installation instruction from pip's home site.
Basically, this consists in:
基本上,这包括:
- downloading get-pip.py. Be sure to do this by following a trusted link since you will have to run the script as root.
- call
sudo python get-pip.py
- 下载get-pip.py。请务必按照受信任的链接执行此操作,因为您必须以 root 身份运行脚本。
- 称呼
sudo python get-pip.py
The main advantage of that solution is that it install pip for the python version that has been used to run get-pip.py, which means that if you use the default OS X installation of python to run get-pip.pyyou will install pip for the python install from the system.
该解决方案的主要优点是它为用于运行的python版本安装pip get-pip.py,这意味着如果您使用python的默认OS X安装来运行,get-pip.py您将从系统安装用于python安装的pip。
Most solutions that use a package manager (homebrew or macport) on OS X create a redundant installation of python in the environment of the package manager which can create inconsistencies in your system since, depending on what you are doing, you may call one installation of python instead of another.
大多数在 OS X 上使用包管理器(自制软件或 macport)的解决方案会在包管理器的环境中创建 python 的冗余安装,这可能会在您的系统中造成不一致,因为根据您在做什么,您可能会调用一个安装python 而不是另一个。
回答by goker.cebeci
To install or upgrade pip, download get-pip.pyfrom http://www.pip-installer.org/en/latest/installing.html
要安装或升级pip,请从http://www.pip-installer.org/en/latest/installing.html下载get-pip.py
Then run the following:
sudo python get-pip.py
然后运行以下命令:
sudo python get-pip.py
For example:
例如:
sudo python Desktop/get-pip.py
Password:
Downloading/unpacking pip
Downloading pip-1.5.2-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Installing collected packages: pip
Successfully installed pip
Cleaning up...
sudo pip install pymongo
Password:
Downloading/unpacking pymongo
Downloading pymongo-2.6.3.tar.gz (324kB): 324kB downloaded
Running setup.py (path:/private/var/folders/0c/jb79t3bx7cz6h7p71ydhwb_m0000gn/T/pip_build_goker/pymongo/setup.py) egg_info for package pymongo
Installing collected packages: pymongo
...
回答by thegauraw
Download this file: get-pip.py
下载此文件:get-pip.py
Then simply type
然后只需键入
sudo python get-pip.py
Make sure you are on the same directory as get-pip.py or you supply the correct path for that file.
确保您与 get-pip.py 位于同一目录中,或者为该文件提供正确的路径。
For details, you can visit: http://pip.readthedocs.org/en/latest/installing.html
回答by user3627034
pipis available on OS X via easy_install.
Open a terminal and type:
pip可在 OS X 上通过easy_install.
打开终端并输入:
sudo easy_install pip
When prompted for a password enter your normal login password.
After the installation has completed you should be able to use pipas expected.
当提示输入密码时,输入您的正常登录密码。
安装完成后,您应该可以pip按预期使用。
note: this works for other python packages too
注意:这也适用于其他 python 包
回答by cbare
Installing a separate copy of Python is a popular option, even though Python already comes with MacOS. You take on the responsibility to make sure you're using the copy of Python you intend. But, the benefits are having the latest Python release and some protection from hosing your system if things go badly wrong.
安装单独的 Python 副本是一种流行的选择,即使 MacOS 已经附带 Python。您有责任确保您使用的是您想要的 Python 副本。但是,好处是拥有最新的 Python 版本,并且在出现严重问题时可以保护您的系统。
To install Python using HomeBrew:
要使用HomeBrew安装 Python :
brew update
brew install python # or brew install python3
Now confirm that we're working with our newly installed Python:
现在确认我们正在使用新安装的 Python:
ls -lh `which python`
...should show a symbolic link to a path with "Cellar" in it like:
...应该显示一个指向带有“Cellar”的路径的符号链接,例如:
lrwxr-xr-x 1 chris admin 35B Dec 2 13:40 /usr/local/bin/python -> ../Cellar/python/2.7.8_2/bin/python
Pip should be installed along with Python. You might want to upgrade it by typing:
Pip 应该与 Python 一起安装。您可能想通过键入以下内容来升级它:
pip install --upgrade pip
Now you're ready to install any of the 50,000+ packages on PyPI.
现在您已准备好在PyPI上安装 50,000 多个软件包中的任何一个。
Other Notes
其他注意事项
Formerly, I've used get-pip.py to install pip. But, the docs warn that get-pip.py does not coordinate with package managers and may leave your system in an inconsistent state. Anyway, there's no need, given that pip is now included with Python as of 2.7.9.
以前,我使用get-pip.py 来安装 pip。但是,文档警告 get-pip.py 不与包管理器协调,并且可能会使您的系统处于不一致的状态。无论如何,没有必要,因为 pip 现在从 2.7.9 开始包含在 Python 中。
Note that pip isn't the only package manager for Python. There's also easy_install. It's no good to mix the two, so don't do it.
请注意,pip 不是 Python 的唯一包管理器。还有easy_install。两者混用是不好的,所以不要这样做。
Finally, if you have both Python 2 and 3 installed, pipwill point to whichever Python you installed last. Get in the habit of explicitly using either pip2or pip3, so you're sure which Python is getting the new library.
最后,如果您同时安装了 Python 2 和 3,pip将指向您最后安装的 Python。养成明确使用pip2或pip3的习惯,这样您就可以确定哪个 Python 正在获取新库。
Happy hacking!
快乐黑客!
回答by Pavan
On Mac:
在 Mac 上:
Install easy_install
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo pythonInstall pip
sudo easy_install pipNow, you could install external modules. For example
pip install regex # This is only an example for installing other modules
安装easy_install
curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python安装点
sudo easy_install pip现在,您可以安装外部模块。例如
pip install regex # This is only an example for installing other modules

