问题:如何在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.

How do I install it?


回答 0

更新(2019年1月):

easy_install弃用。请get-pip.py改用:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

旧答案:

easy_install pip

如果您需要管理员权限才能运行此程序,请尝试:

sudo easy_install pip

UPDATE (Jan 2019):

easy_install has been deprecated. Please use get-pip.py instead:

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

回答 1

⚡️ TL; DR -一个线的解决方案。

您要做的就是:

sudo easy_install pip

2019:⚠️ easy_install已被弃用。检查下面的方法2以进行首选安装!

我做了一个gif,因为。为什么不?

在Mac上安装PIP

细节:

⚡️好,我读了上面给出的解决方案,但这是一个易于安装的解决方案pip

MacOS Python已安装。但是要确保已Python安装,请打开终端并运行以下命令。

python --version

如果此命令返回的版本号表示Python存在。这也意味着您已经可以easy_install考虑使用macOS/OSX

Now️现在,您所要做的就是运行以下命令。

sudo easy_install pip

之后,pip将被安装,您将可以使用它来安装其他软件包。

如果您以pip这种方式安装有任何问题,请告诉我。

干杯!

PS我最终在博客上写了一篇有关它的文章。快速提示:如何在macOS或OS X上安装pip?


更新(2019年1月):方法2:两线解决方案-

easy_install弃用。请get-pip.py改用。

首先下载get-pip文件

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

现在运行此文件进行安装 pip

python get-pip.py

那应该做。

你说的另一个gif?来呀!

手动安装点子

⚡️ TL;DR — One line solution.

All you have to do is:

sudo easy_install pip

2019: ⚠️easy_install has been deprecated. Check Method #2 below for preferred installation!

I made a gif, coz. why not?

Install PIP on Mac

Details:

⚡️ OK, I read the solutions given above, but here’s an EASY solution to install pip.

MacOS comes with Python installed. But to make sure that you have Python installed open the terminal and run the following command.

python --version

If this command returns a version number that means Python exists. Which also means that you already have access to easy_install considering you are using macOS/OSX.

ℹ️ Now, all you have to do is run the following command.

sudo easy_install pip

After that, pip will be installed and you’ll be able to use it for installing other packages.

Let me know if you have any problems installing pip this way.

Cheers!

P.S. I ended up blogging a post about it. QuickTip: How Do I Install pip on macOS or OS X?


UPDATE (Jan 2019): METHOD #2: Two line solution —

easy_install has been deprecated. Please use get-pip.py instead.

First of all download the get-pip file

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Now run this file to install pip

python get-pip.py

That should do it.

Another gif you said? Here ya go!

Manual install of pip


回答 2

您可以在OS X上通过Homebrew安装它。为什么要在Homebrew中安装Python?

OS X附带的Python版本非常适合学习,但不利于开发。OS X附带的版本可能已从官方的当前Python发行版过时了,该版本被认为是稳定的生产版本。(来源

Homebrew是OS X的软件包管理器。在Homebrew页面上找到更多详细信息。一旦安装了Homebrew,请运行以下命令以安装最新的Python,Pip和Setuptools:

brew install python

You can install it through Homebrew on OS X. Why would you install Python with Homebrew?

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)

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:

brew install python

回答 3

我很惊讶没有人提到这一点-自2013年以来,python本身就可以安装pip,不需要外部命令(也不需要Internet连接)。

sudo -H python -m ensurepip

这将创建与安装类似的安装easy_install

I’m surprised no-one has mentioned this – since 2013, python itself is capable of installing pip, no external commands (and no internet connection) required.

sudo -H python -m ensurepip

This will create a similar install to what easy_install would.


回答 4

在Mac上:

  1. 安装easy_install

    curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
  2. 安装点子

    sudo easy_install pip
  3. 现在,您可以安装外部模块。例如

    pip install regex   # This is only an example for installing other modules

On Mac:

  1. Install easy_install

    curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python
    
  2. Install pip

    sudo easy_install pip
    
  3. Now, you could install external modules. For example

    pip install regex   # This is only an example for installing other modules
    

回答 5

pip可通过OS X在OS X上使用easy_install
打开一个终端并输入:

sudo easy_install pip

当提示您输入密码时,输入您的常规登录密码。
安装完成后,您应该可以pip按预期使用。

注意:这也适用于其他python包

pip is available on OS X via easy_install.
Open a terminal and type:

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 pip as expected.

note: this works for other python packages too


回答 6

2019年10月更新:MacOs Mojave

MacOS附带python2,但不附带pip。无论如何,最好使用自制软件进行管理,您必须在安装之前进行安装:

https://docs.brew.sh/安装

安装python2:

brew install python

警告:对于现代macOS(2019),可以安装python3,并且python2您确实需要执行以下操作:brew install python@2

安装python3:

brew install python3

更新:Python 3

如果您安装python3,则会自动安装pip。

brew install python3

新2019:现在使用pip版本3,请使用pip3或您可以执行:python3使用版本3.当您使用pip3安装软件包时,它们将与分开python2

老:您只需要升级pip,但在此之前,您需要创建一个虚拟环境以使用Python3。您可以使用项目文件夹或任何文件夹:

python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip

检查版本:

pip -V
python --version

NEW 2019:
pip3 -V
python3 --version

要停用环境:

$ deactivate

UPDATED 2019 October: MacOs Mojave

MacOS comes with python2, but not with pip. Anyway, it’s better to manage it with homebrew, you must install it before:

https://docs.brew.sh/Installation

Install python2:

brew install python

WARNING: for a modern macOS (2019) this can install python3, and for python2 you really need to do: brew install python@2

Install python3:

brew install python3

UPDATE: Python 3

If you install python3, pip will be installed automatically.

brew install python3

NEW 2019: now to use pip version 3, use pip3 , or you can execute: python3, to use version 3. When you install packages with pip3 they will be separated from python2.

OLD: You need only to upgrade pip, but before that you need create a virtual environment to work with Python 3. You can use a project folder or any folder:

python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip

Check the versions:

pip -V
python --version

NEW 2019:
pip3 -V
python3 --version

To deactivate the environment:

$ deactivate

回答 7

最简单的解决方案是按照pip主页上安装说明进行操作

基本上,这包括:

  • 下载get-pip.py。确保通过遵循受信任的链接来执行此操作,因为您将必须以root用户身份运行脚本。
  • 呼叫 sudo python get-pip.py

该解决方案的主要优点是,它会为曾经运行过的python版本安装pip get-pip.py,这意味着,如果使用默认的OS X python安装来运行get-pip.py,则将从系统中为python安装安装pip。

大多数在OS X上使用软件包管理器(自制或Macport)的解决方案都会在软件包管理器的环境中创建python的冗余安装,这可能会在您的系统中造成不一致,因为根据您所执行的操作,您可以将安装称为python,而不是另一个。

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

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.

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.


回答 8

尽管Python已随MacOS一起提供,但安装单独的Python副本是一种普遍的选择。您有责任确保使用的是您打算使用的Python副本。但是,这样做的好处是拥有最新的Python版本,并且在出现严重错误的情况下可以防止系统崩溃。

要使用HomeBrew安装Python :

brew update
brew install python # or brew install python3

现在确认我们正在使用新安装的Python:

ls -lh `which python`

…应显示指向其中带有“地窖”的路径的符号链接,例如:

lrwxr-xr-x  1 chris  admin    35B Dec  2 13:40 /usr/local/bin/python -> ../Cellar/python/2.7.8_2/bin/python

Pip应该与Python一起安装。您可能需要输入以下内容来升级它:

pip install --upgrade pip

现在,您可以在PyPI上安装任何50,000+个软件包。

其他注意事项

以前,我使用get-pip.py安装pip。但是,文档警告说,get-pip.py与软件包管理器不协调,可能会使您的系统处于不一致状态。无论如何,没有必要,因为从2.7.9开始,Python现在已包含 pip 。

请注意,pip不是Python的唯一软件包管理器。还有easy_install。将两者混合使用是不好的,所以不要这样做。

最后,如果您同时安装了Python 2和3,pip将指向最后安装的Python。养成显式使用pip2pip3的习惯,因此您可以确定哪个Python正在获取新库。

骇客入侵!

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.

To install Python using HomeBrew:

brew update
brew install python # or brew install python3

Now confirm that we’re working with our newly installed Python:

ls -lh `which python`

…should show a symbolic link to a path with “Cellar” in it like:

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 install --upgrade pip

Now you’re ready to install any of the 50,000+ packages on PyPI.

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.

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.

Finally, if you have both Python 2 and 3 installed, pip will point to whichever Python you installed last. Get in the habit of explicitly using either pip2 or pip3, so you’re sure which Python is getting the new library.

Happy hacking!


回答 9

对于同时安装了python2和python3的用户,以下是解决方案:

python2.7 -m ensurepip --default-pip

另外,如果您想为python3.6安装pip:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

For those who have both python2 & python3 installed, here’s the solution:

python2.7 -m ensurepip --default-pip

Additionally, if you wanna install pip for python3.6:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

回答 10

在最新版本(我相信至少从塞拉利昂起,从优胜美地或El Capitan起),如果您使用自制软件brew postinstall python3brew install python3则需要运行。

所以,

brew install python3 # this only installs python
brew postinstall python3 # this installs pip

更新-1.5之后的自制软件版本

根据官方的Homebrew页面

在2018年3月1日,python公式将升级到Python 3.x,并且将添加python @ 2公式以安装Python 2.7(尽管这仅是小桶,因此默认情况下,不将python和python2添加到PATH中,而无需手动冲泡链接–force)。我们将维护python2,python3和python @ 3别名。

因此,要安装Python 3,请运行以下命令:

brew install python3

然后,pip会自动安装,您可以通过来安装任何软件包pip install <package>

On the recent version (from Yosemite or El Capitan I believe… at least from Sierra onward), you need to run brew postinstall python3 after brew install python3 if you use homebrew.

So,

brew install python3 # this only installs python
brew postinstall python3 # this installs pip

UPDATED – Homebrew version after 1.5

According to the official Homebrew page:

On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link –force). We will maintain python2, python3 and python@3 aliases.

So to install Python 3, run the following command:

brew install python3

Then, the pip is installed automatically, and you can install any package by pip install <package>.


回答 11

下载此文件:get-pip.py

然后只需键入

sudo python get-pip.py

确保您与get-pip.py位于同一目录中,或者为该文件提供正确的路径。

有关详细信息,您可以访问:http : //pip.readthedocs.org/en/latest/installing.html

或者,http://thegauraw-blog-blog.tumblr.com/post/47601704154/how-to-install-pip-in-both-windows-ubuntu-easiest-way

Download this file: 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.

For details, you can visit: http://pip.readthedocs.org/en/latest/installing.html

or, http://thegauraw-blog-blog.tumblr.com/post/47601704154/how-to-install-pip-in-both-windows-ubuntu-easiest-way


回答 12

您应该先安装Brew:

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

然后brew安装Python

brew install python

然后pip会工作

You should install Brew first:

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

Then brew install Python

brew install python

Then pip will work


回答 13

如果要“ pip3”,可以执行以下操作:

通过酿造: brew install python3

在此处输入图片说明

然后你可以执行

pip3 <command> [options]

If you want “pip3” you can do the ff:

via brew: brew install python3

enter image description here

then you can execute

pip3 <command> [options]


回答 14

$ sudo port install py27-pip

然后更新您的PATH以包含py27-pip bin目录(您可以将其添加到〜/ .bash_profile PATH = / opt / local / Library / Frameworks / Python.framework / Versions / 2.7 / bin:$ PATH中)

点子将在新的终端窗口中可用。

$ 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

pip will be available in new terminal window.


回答 15

要安装或升级piphttp://www.pip-installer.org/en/latest/installing.html下载get-pip.py

然后运行以下命令: sudo python get-pip.py

例如:

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
...

To install or upgrade pip, download get-pip.py from http://www.pip-installer.org/en/latest/installing.html

Then run the following: 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
...

回答 16

无需安装 sudo

如果您想要安装pip而不需要sudo,那么在尝试全局安装软件包时总是会感到沮丧,请像这样pip在本地文件夹中安装/usr/local

curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
python get-pip.py --prefix=/usr/local/

然后:

pip install <package-of-choice> 没有 sudo

Install without the need for sudo

If you want to install pip without the need for sudo, which is always frustrating when trying to install packages globally, install pip in your local folder /usr/local like this:

curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
python get-pip.py --prefix=/usr/local/

and then:

pip install <package-of-choice> without sudo


回答 17

首先安装python3,然后使用pip3安装软件包。

brew install python

将会安装python3,并且pip附带了它。要使用pip安装一些软件包,请运行以下命令

pip3 install package

注意它是pip3,因为您想使用python3。

Install python3 first, then use pip3 to install packages.

brew install python

python3 will be installed, and pip is shipped with it. To use pip to install some package, run the following

pip3 install package

Notice it’s pip3 because you want to use python3.


回答 18

从以下网站下载python设置工具:

https://pypi.python.org/pypi/setuptools

使用tar文件。

下载后,转到下载的文件夹并运行

python setup.py install

完成后,您将拥有easy_install。

请使用以下内容安装pip:

sudo easy_install pip

Download python setup tools from the below website:

https://pypi.python.org/pypi/setuptools

Use the tar file.

Once you download, go to the downloaded folder and run

python setup.py install

Once you do that,you will have easy_install.

Use the below then to install pip:

sudo easy_install pip

回答 19

以某种方式无法轻松安装在我的旧Mac(10.8)上不起作用。这解决了我的问题。

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

如果没有wget,只需在浏览器中打开,https://bootstrap.pypa.io/get-pip.py然后另存为get-pip.py

Somehow easy install doesn’t work on my old mac (10.8). This solve my problem.

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

If you do not have wget, just open in browser https://bootstrap.pypa.io/get-pip.py then save as get-pip.py


回答 20

我向您推荐水蟒。它是由Python支持的领先的开放数据科学平台。安装了许多基本软件包。Anaconda(conda)附带了它自己的安装pip

I recommend Anaconda to you. It’s the leading open data science platform powered by Python. There are many basic packages installed. Anaconda (conda) comes with its own installation of pip.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。