如何在MacOS上安装Pip?

本文是一篇关于在MacOS上安装Pip的教程,包括使用easy_install、get-pip.py脚本和brew的方法。文章还介绍了如何检查Python和Pip的版本,以确保正确安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python is very popular programming and scripting language. It provides useful modules and libraries but also there is a lot of popular 3rd party library. Pip is the command and tools used to install, update and remove 3rd party packages. In this tutorial, we will learn how to install pip and some useful information.

Python是非常流行的编程和脚本语言。 它提供了有用的模块和库,但是也有很多流行的第三方库。 Pip是用于安装,更新和删除第三方软件包的命令和工具。 在本教程中,我们将学习如何安装pip和一些有用的信息。

检查并显示Python版本 (Check and Display Python Version)

Before installing the pip we have to be sure that Python is installed. Also, the version of the Python is important because pip will be installed according to this Python version.

在安装pip之前,我们必须确保已安装Python。 同样,Python版本很重要,因为pip将根据此Python版本安装。

$ python --version

$ python3 --version
Check and Display Python Version
Check and Display Python Version
检查并显示Python版本

We can see that both PYthon2 and PYthon3 is installed. So we can use installation commands for both Python2 and Python3. The python2 version is Python2.7.16 and Python3 version is Python3.6.8 .

我们可以看到同时安装了PYthon2和PYthon3。 因此,我们可以为Python2和Python3使用安装命令。 python2版本为Python2.7.16和Python3版本为Python3.6.8

在MacOS上使用easy_install安装Pip (Install Pip with easy_install On MacOS)

easy_install is a Python module bundled with setuptools which gives us the ability to download, build, install, and manage Python packages. Before pip easy_install was the standard package manager for the Python. We can install pip with the easy_install command like below.

easy_install是与setuptools捆绑在一起的Python模块,它使我们能够下载,构建,安装和管理Python软件包。 在pip easy_install之前是Python的标准软件包管理器。 我们可以使用easy_install命令安装pip,如下所示。

$ sudo easy_install pip

If the pip is already installed we can also upgrade the existing pip installation with the easy_install like below. We will use the pip command because it installed already and provide the --upgrade option with the package name which is also pip.

如果已经安装了pip,我们还可以使用easy_install升级现有的pip安装,如下所示。 我们将使用pip命令,因为它已经安装,并为--upgrade选项提供了包名,也就是pip。

$ sudo pip install --upgrade pip

在MacOS上使用get-pip.py安装Pip (Install Pip with get-pip.py On MacOS)

get-pip.py is another way to install pip in MacOS. get-pip.py is a Python script that will simply download and install the Pip package for Python. First, we will download the get-pip.py script with the curl command. We will provide the URL with the -o option where we will set the name of the downloaded get-pip.py file name.

get-pip.py是在MacOS中安装pip的另一种方法。 get-pip.py是一个Python脚本,将仅下载并安装适用于Python的Pip软件包。 首先,我们将使用curl命令下载get-pip.py脚本。 我们将为URL提供-o选项,其中将设置下载的get-pip.py文件名的名称。

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

AND then we will call the get-pip.py with the Python interpreter. This will run the get-pip.py file Python codes which will simply install the pip for the macOS or OS X.

然后,我们将使用Python解释器调用get-pip.py。 这将运行get-pip.py文件Python代码,该代码将简单地为macOS或OS X安装pip。

$ python get-pip.py
Install Pip with get-pip.py On MacOS
Install Pip with get-pip.py On MacOS
在MacOS上使用get-pip.py安装Pip

在MacOS上使用brew安装Pip (Install Pip with brew On MacOS)

Homebrew is the package management tool for the macOS. We can use Homebrew in order to install Python and pip. pip is provided with the python package. We will use brew command with the install command like below.

Homebrew是macOS的软件包管理工具。 我们可以使用Homebrew来安装Python和pip。 python软件包提供了pip。 我们将brew命令与install命令一起使用,如下所示。

$ brew install python

If there are problems related to the pip usage we may need to relink the python with the following command.

如果存在与点子用法有关的问题,我们可能需要使用以下命令重新链接python。

$ brew unlink python && brew link python

检查并显示点的版本 (Check and Display Pip Version)

We can check installed pip version with the -V or --version option like below.

我们可以使用-V--version选项检查已安装的pip版本,如下所示。

$ pip -V
 
$ pip3 -V
Install Pip with brew On MacOS
Install Pip with brew On MacOS
在MacOS上使用brew安装Pip

We can see that Python2 pip version is pip 9.0.1 and Python3 pip version is pip 9.0.1 . They are the same version for both Python2 and Python3. This is because to prevent version conflicts and synchronize the feature development of the pip command for both Python versions.

我们可以看到Python2 pip版本是pip 9.0.1 ,Python3 pip版本是pip 9.0.1 。 对于Python2和Python3,它们是相同的版本。 这是因为为了防止版本冲突并针对两个Python版本同步pip命令的功能开发。

LEARN MORE  How To Update/Upgrade A Python Package with Pip?
了解更多如何使用Pip更新/升级Python软件包?

翻译自: https://www.poftut.com/how-to-install-pip-on-macos/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值