如何在macOS或OS X上安装pip?

本文翻译自:How do I install pip on macOS or OS X?

This post is a Community Wiki . 这篇文章是社区维基 Edit existing answers to improve this post. 编辑现有答案以改善此职位。 It is not currently accepting new answers. 它当前不接受新的答案。 Learn more . 了解更多

I spent most of the day yesterday searching for a clear answer for installing pip (package manager for Python). 昨天我大部分时间都在寻找安装pip (Python的软件包管理器)的明确答案。 I can't find a good solution. 我找不到一个好的解决方案。

How do I install it? 如何安装?


#1楼

参考:https://stackoom.com/question/1AT3f/如何在macOS或OS-X上安装pip


#2楼

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. OS X附带的Python版本非常适合学习,但不利于开发。 The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version. OS X附带的版本可能已从官方的当前Python发行版过时了,该版本被认为是稳定的生产版本。 ( source ) 来源

Homebrew is something of a package manager for OS X. Find more details on the Homebrew page . Homebrew是OS X的软件包管理器。在Homebrew页面上找到更多详细信息。 Once Homebrew is installed, run the following to install the latest Python, Pip & Setuptools: 一旦安装了Homebrew,请运行以下命令以安装最新的Python,Pip和Setuptools:

brew install python

#3楼

easy_install pip

If you need admin privileges to run this, try: 如果您需要管理员权限才能运行此程序,请尝试:

sudo easy_install pip

UPDATE (Jan 2019): 更新(2019年1月):

easy_install has been deprecated . easy_install已被弃用 Please use get-pip.py instead. 请改用get-pip.py


#4楼

$ 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. 点子将在新的终端窗口中可用。


#5楼

You should install Brew first: 您应该先安装Brew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then brew install Python 然后brew安装Python

brew install python

Then pip will work 然后pip就会起作用


#6楼

The simplest solution is to follow the installation instruction from pip's home site . 最简单的解决方案是按照pip主页上安装说明进行操作

Basically, this consists in: 基本上,这包括:

  • downloading get-pip.py . 下载get-pip.py Be sure to do this by following a trusted link since you will have to run the script as root. 确保通过遵循受信任的链接来执行此操作,因为您将必须以root用户身份运行脚本。
  • call sudo python get-pip.py 调用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.py you will install pip for the python install from the system. 该解决方案的主要优点是,它为用于运行get-pip.py的python版本安装pip,这意味着,如果您使用默认的OS X安装python来运行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,而不是另一个。

发布了0 篇原创文章 · 获赞 72 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105197613